<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>The CppAD::vector Template Class</title>
<meta name="description" id="description" content="The CppAD::vector Template Class"/>
<meta name="keywords" id="keywords" content=" vector Cppad template class assignment [] push_back push_vector push data vectorbool thread_alloc exercise Cppad::vector "/>
<style type='text/css'>
body { color : black }
body { background-color : white }
A:link { color : blue }
A:visited { color : purple }
A:active { color : purple }
</style>
<script type='text/javascript' language='JavaScript' src='_cppad_vector_xml.js'>
</script>
</head>
<body>
<table><tr>
<td>
<a href="http://www.coin-or.org/CppAD/" target="_top"><img border="0" src="_image.gif"/></a>
</td>
<td><a href="ode_gear_control.cpp.xml" target="_top">Prev</a>
</td><td><a href="cppad_vector.cpp.xml" target="_top">Next</a>
</td><td>
<select onchange='choose_across0(this)'>
<option>Index-&gt;</option>
<option>contents</option>
<option>reference</option>
<option>index</option>
<option>search</option>
<option>external</option>
</select>
</td>
<td>
<select onchange='choose_up0(this)'>
<option>Up-&gt;</option>
<option>CppAD</option>
<option>library</option>
<option>CppAD_vector</option>
</select>
</td>
<td>
<select onchange='choose_down2(this)'>
<option>CppAD-&gt;</option>
<option>Install</option>
<option>Introduction</option>
<option>AD</option>
<option>ADFun</option>
<option>preprocessor</option>
<option>multi_thread</option>
<option>library</option>
<option>ipopt_solve</option>
<option>Example</option>
<option>speed</option>
<option>Appendix</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>library-&gt;</option>
<option>ErrorHandler</option>
<option>NearEqual</option>
<option>speed_test</option>
<option>SpeedTest</option>
<option>time_test</option>
<option>NumericType</option>
<option>CheckNumericType</option>
<option>SimpleVector</option>
<option>CheckSimpleVector</option>
<option>nan</option>
<option>pow_int</option>
<option>Poly</option>
<option>LuDetAndSolve</option>
<option>RombergOne</option>
<option>RombergMul</option>
<option>Runge45</option>
<option>Rosen34</option>
<option>OdeErrControl</option>
<option>OdeGear</option>
<option>OdeGearControl</option>
<option>CppAD_vector</option>
<option>thread_alloc</option>
<option>index_sort</option>
<option>BenderQuad</option>
<option>opt_val_hes</option>
<option>LuRatio</option>
</select>
</td>
<td>
<select onchange='choose_down0(this)'>
<option>CppAD_vector-&gt;</option>
<option>cppad_vector.cpp</option>
<option>vector_bool.cpp</option>
</select>
</td>
<td>
<select onchange='choose_current0(this)'>
<option>Headings-&gt;</option>
<option>Syntax</option>
<option>Description</option>
<option>Include</option>
<option>capacity</option>
<option>Assignment</option>
<option>---..Check Size</option>
<option>---..Return Reference</option>
<option>---..Move Semantics</option>
<option>Element Access</option>
<option>push_back</option>
<option>push_vector</option>
<option>Output</option>
<option>resize</option>
<option>clear</option>
<option>data</option>
<option>vectorBool</option>
<option>---..Memory</option>
<option>---..data</option>
<option>---..Output</option>
<option>---..Element Type</option>
<option>Memory and Parallel Mode</option>
<option>Example</option>
<option>Exercise</option>
</select>
</td>
</tr></table><br/>







<center><b><big><big>The CppAD::vector Template Class</big></big></b></center>
<br/>
<b><big><a name="Syntax" id="Syntax">Syntax</a></big></b>

<code><font color="blue"><br/>
# include &lt;cppad/vector.hpp&gt;</font></code>

<br/>
<br/>
<b><big><a name="Description" id="Description">Description</a></big></b>
<br/>
The include file <code><font color="blue">cppad/vector.hpp</font></code> defines the
vector template class <code><font color="blue">CppAD::vector</font></code>.
This is a <a href="simplevector.xml" target="_top"><span style='white-space: nowrap'>SimpleVector</span></a>
 template class and in addition
it has the features listed below:

<br/>
<br/>
<b><big><a name="Include" id="Include">Include</a></big></b>
<br/>
The file <code><font color="blue">cppad/vector.hpp</font></code> is included by <code><font color="blue">cppad/cppad.hpp</font></code>
but it can also be included separately with out the rest of the 
CppAD include files.

<br/>
<br/>
<b><big><a name="capacity" id="capacity">capacity</a></big></b>
<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is a 
<code><font color="blue"><span style='white-space: nowrap'>CppAD::vector&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>
,
and 
<code><i><font color="black"><span style='white-space: nowrap'>cap</span></font></i></code>
 is a <code><font color="blue">size_t</font></code> object,

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>cap</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.capacity()<br/>
</span></font></code>
set 
<code><i><font color="black"><span style='white-space: nowrap'>cap</span></font></i></code>
 to the number of 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
 objects that
could fit in the memory currently allocated for 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
.
Note that

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.size()&#xA0;&lt;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.capacity()<br/>
</span></font></code>
<br/>
<b><big><a name="Assignment" id="Assignment">Assignment</a></big></b>

<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 and 
<code><i><font color="black"><span style='white-space: nowrap'>y</span></font></i></code>
 are 

<code><font color="blue"><span style='white-space: nowrap'>CppAD::vector&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>
 objects,

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
has all the properties listed for a
<a href="simplevector.xml#Assignment" target="_top"><span style='white-space: nowrap'>simple&#xA0;vector&#xA0;assignment</span></a>

plus the following:

<br/>
<br/>
<b><a name="Assignment.Check Size" id="Assignment.Check Size">Check Size</a></b>
<br/>
The <code><font color="blue">CppAD::vector</font></code> template class will check that
the size of 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is either zero or the size of 
<code><i><font color="black"><span style='white-space: nowrap'>y</span></font></i></code>

before doing the assignment.
If this is not the case, <code><font color="blue">CppAD::vector</font></code> will use
<a href="errorhandler.xml" target="_top"><span style='white-space: nowrap'>ErrorHandler</span></a>

to generate an appropriate error report.
Allowing for assignment to a vector with size zero makes the following
code work:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;CppAD::vector&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'>;<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>;<br/>
</span></font></code>
<br/>
<b><a name="Assignment.Return Reference" id="Assignment.Return Reference">Return Reference</a></b>
<br/>
A reference to the vector 
<code><i><font color="black"><span style='white-space: nowrap'>y</span></font></i></code>
 is returned.
An example use of this reference is in multiple assignments of the form

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>z</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
<br/>
<b><a name="Assignment.Move Semantics" id="Assignment.Move Semantics">Move Semantics</a></b>
<br/>
If the C++ compiler supports move semantic rvalues using the <code><font color="blue">&amp;&amp;</font></code>
syntax, then it will be used during the vector assignment statement.
This means that return values and other temporaries are not be copied,
but rather pointers are transferred.

<br/>
<br/>
<b><big><a name="Element Access" id="Element Access">Element Access</a></big></b>


<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is a 
<code><font color="blue"><span style='white-space: nowrap'>CppAD::vector&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>
 object
and <code><font color="blue">i</font></code> has type <code><font color="blue">size_t</font></code>,

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]<br/>
</span></font></code>
has all the properties listed for a
<a href="simplevector.xml#Element Access" target="_top"><span style='white-space: nowrap'>simple&#xA0;vector&#xA0;element&#xA0;access</span></a>

plus the following:
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>The object 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]</span></font></code>
 has type 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>

(is not possibly a different type that can be converted to 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
).
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>If 
<code><i><font color="black"><span style='white-space: nowrap'>i</span></font></i></code>
 is not less than the size of the 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
,
<code><font color="blue">CppAD::vector</font></code> will use
<a href="errorhandler.xml" target="_top"><span style='white-space: nowrap'>ErrorHandler</span></a>

to generate an appropriate error report.

<br/>
<br/>
<b><big><a name="push_back" id="push_back">push_back</a></big></b>


<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is a 
<code><font color="blue"><span style='white-space: nowrap'>CppAD::vector&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>
 object
with size equal to 
<code><i><font color="black"><span style='white-space: nowrap'>n</span></font></i></code>
 and

<code><i><font color="black"><span style='white-space: nowrap'>s</span></font></i></code>
 has type 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
,

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.push_back(</span></font><i><font color="black"><span style='white-space: nowrap'>s</span></font></i><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>
extends the vector 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 so that its new size is 
<code><i><font color="black"><span style='white-space: nowrap'>n</span></font></i></code>
 plus one
and 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>n</span></font></i><font color="blue"><span style='white-space: nowrap'>]</span></font></code>
 is equal to 
<code><i><font color="black"><span style='white-space: nowrap'>s</span></font></i></code>

(equal in the sense of the 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
 assignment operator).

<br/>
<br/>
<b><big><a name="push_vector" id="push_vector">push_vector</a></big></b>


<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is a 
<code><font color="blue"><span style='white-space: nowrap'>CppAD::vector&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>
 object
with size equal to 
<code><i><font color="black"><span style='white-space: nowrap'>n</span></font></i></code>
 and

<code><i><font color="black"><span style='white-space: nowrap'>v</span></font></i></code>
 is a <a href="simplevector.xml" target="_top"><span style='white-space: nowrap'>simple&#xA0;vector</span></a>

with elements of type 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
 and size 
<code><i><font color="black"><span style='white-space: nowrap'>m</span></font></i></code>
,

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.push_vector(</span></font><i><font color="black"><span style='white-space: nowrap'>v</span></font></i><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>
extends the vector 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 so that its new size is 
<code><i><font color="black"><span style='white-space: nowrap'>n</span></font></i><font color="blue"><span style='white-space: nowrap'>+</span></font><i><font color="black"><span style='white-space: nowrap'>m</span></font></i></code>

and 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>n</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;+&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]</span></font></code>
 is equal to 
<code><i><font color="black"><span style='white-space: nowrap'>v</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]</span></font></code>

for 
<code><i><font color="black"><span style='white-space: nowrap'>i&#xA0;=&#xA0;1&#xA0;,&#xA0;...&#xA0;,&#xA0;m-1</span></font></i></code>

(equal in the sense of the 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
 assignment operator).

<br/>
<br/>
<b><big><a name="Output" id="Output">Output</a></big></b>
<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is a 
<code><font color="blue"><span style='white-space: nowrap'>CppAD::vector&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>
 object
and 
<code><i><font color="black"><span style='white-space: nowrap'>os</span></font></i></code>
 is an <code><font color="blue">std::ostream</font></code>,
and the operation

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>os</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&lt;&lt;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
will output the vector 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 to the standard
output stream 
<code><i><font color="black"><span style='white-space: nowrap'>os</span></font></i></code>
.
The elements of 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 are enclosed at the beginning by a
<code><font color="blue">{</font></code> character,
they are separated by <code><font color="blue">,</font></code> characters,
and they are enclosed at the end by <code><font color="blue">}</font></code> character.
It is assumed by this operation that if 
<code><i><font color="black"><span style='white-space: nowrap'>e</span></font></i></code>

is an object with type 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
,

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>os</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&lt;&lt;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>e</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
will output the value 
<code><i><font color="black"><span style='white-space: nowrap'>e</span></font></i></code>
 to the standard
output stream 
<code><i><font color="black"><span style='white-space: nowrap'>os</span></font></i></code>
.

<br/>
<br/>
<b><big><a name="resize" id="resize">resize</a></big></b>
<br/>
The call 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.resize(</span></font><i><font color="black"><span style='white-space: nowrap'>n</span></font></i><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
 set the size of 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 equal to 

<code><i><font color="black"><span style='white-space: nowrap'>n</span></font></i></code>
. 
If 
<code><i><font color="black"><span style='white-space: nowrap'>n</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&lt;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.capacity()</span></font></code>
, 
no memory is freed or allocated and the capacity of 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 does not change.

<br/>
<br/>
<b><big><a name="clear" id="clear">clear</a></big></b>
<br/>
All memory allocated for the vector is freed
and both its size and capacity are set to zero.
The can be useful when using very large vectors
and when checking for memory leaks (and there are global vectors)
see the <a href="cppad_vector.xml#Memory and Parallel Mode" target="_top"><span style='white-space: nowrap'>memory</span></a>
 discussion.

<br/>
<br/>
<b><big><a name="data" id="data">data</a></big></b>


<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is a 
<code><font color="blue"><span style='white-space: nowrap'>CppAD::vector&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>
 object

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.data()<br/>
</span></font></code>
returns a pointer to a 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
 object such that for

<code><font color="blue"><span style='white-space: nowrap'>0&#xA0;&lt;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&lt;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.size()</span></font></code>
,

<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]</span></font></code>
 and 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.data()[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]</span></font></code>
 
are the same 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
 object.
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is <code><font color="blue">const</font></code>, the pointer is <code><font color="blue">const</font></code>.
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.capacity()</span></font></code>
 is zero, the value of the pointer is not defined.
The pointer may no longer be valid after the following operations on 

<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
:
its destructor,
<code><font color="blue">clear</font></code>,
<code><font color="blue">resize</font></code>, 
<code><font color="blue">push_back</font></code>,
<code><font color="blue">push_vector</font></code>,
assignment to another vector when original size of 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is zero. 

<br/>
<br/>
<b><big><a name="vectorBool" id="vectorBool">vectorBool</a></big></b>

<br/>
The file <code><font color="blue">&lt;cppad/vector.hpp&gt;</font></code> also defines the class
<code><font color="blue">CppAD::vectorBool</font></code>.
This has the same specifications as <code><font color="blue">CppAD::vector&lt;bool&gt;</font></code> 
with the following exceptions:

<br/>
<br/>
<b><a name="vectorBool.Memory" id="vectorBool.Memory">Memory</a></b>
<br/>
The class <code><font color="blue">vectorBool</font></code> conserves on memory
(on the other hand, <code><font color="blue">CppAD::vector&lt;bool&gt;</font></code> is expected to be faster
than <code><font color="blue">vectorBool</font></code>).

<br/>
<br/>
<b><a name="vectorBool.data" id="vectorBool.data">data</a></b>
<br/>
The <a href="cppad_vector.xml#data" target="_top"><span style='white-space: nowrap'>data</span></a>
 function is not supported by
<code><font color="blue">vectorBool</font></code>.

<br/>
<br/>
<b><a name="vectorBool.Output" id="vectorBool.Output">Output</a></b>
<br/>
The <code><font color="blue">CppAD::vectorBool</font></code> output operator
prints each boolean value as 
a <code><font color="blue">0</font></code> for false,
a <code><font color="blue">1</font></code> for true, 
and does not print any other output; i.e.,
the vector is written a long sequence of zeros and ones with no
surrounding <code><font color="blue">{</font></code>, <code><font color="blue">}</font></code> and with no separating commas or spaces. 

<br/>
<br/>
<b><a name="vectorBool.Element Type" id="vectorBool.Element Type">Element Type</a></b>
<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 has type <code><font color="blue">vectorBool</font></code>
and 
<code><i><font color="black"><span style='white-space: nowrap'>i</span></font></i></code>
 has type <code><font color="blue">size_t</font></code>,
the element access value 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]</span></font></code>
 has an unspecified type,
referred to here as 
<code><i><font color="black"><span style='white-space: nowrap'>elementType</span></font></i></code>
, that supports the following
operations:

<ol type="1"><li>

<code><i><font color="black"><span style='white-space: nowrap'>elementType</span></font></i></code>
 can be converted to <code><font color="blue">bool</font></code>; e.g.
the following syntax is supported:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;static_cast&lt;bool&gt;(&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]&#xA0;)<br/>
</span></font></code>
</li><li>

<code><i><font color="black"><span style='white-space: nowrap'>elementType</span></font></i></code>
 supports the assignment operator <code><font color="blue">=</font></code> where the 
right hand side is a <code><font color="blue">bool</font></code> or an 
<code><i><font color="black"><span style='white-space: nowrap'>elementType</span></font></i></code>
 object; e.g.,
if 
<code><i><font color="black"><span style='white-space: nowrap'>y</span></font></i></code>
 has type <code><font color="blue">bool</font></code>, the following syntax is supported:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
</li><li>
The result of an assignment to an 
<code><i><font color="black"><span style='white-space: nowrap'>elementType</span></font></i></code>

also has type 
<code><i><font color="black"><span style='white-space: nowrap'>elementType</span></font></i></code>
. 
Thus, if 
<code><i><font color="black"><span style='white-space: nowrap'>z</span></font></i></code>
 has type <code><font color="blue">bool</font></code>, the following syntax is supported:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>z</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
</li></ol>
<br/>
<b><big><a name="Memory and Parallel Mode" id="Memory and Parallel Mode">Memory and Parallel Mode</a></big></b>


<br/>
These vectors use the multi-threaded fast memory allocator 
<a href="thread_alloc.xml" target="_top"><span style='white-space: nowrap'>thread_alloc</span></a>
:

<ol type="1"><li>
The routine <a href="ta_parallel_setup.xml" target="_top"><span style='white-space: nowrap'>parallel_setup</span></a>
 must
be called before these vectors can be used 
<a href="ta_in_parallel.xml" target="_top"><span style='white-space: nowrap'>in&#xA0;parallel</span></a>
.
</li><li>

Using these vectors affects the amount of memory 
<a href="ta_inuse.xml" target="_top"><span style='white-space: nowrap'>in_use</span></a>
 and <a href="ta_available.xml" target="_top"><span style='white-space: nowrap'>available</span></a>
.
</li><li>

Calling <a href="cppad_vector.xml#clear" target="_top"><span style='white-space: nowrap'>clear</span></a>
,
makes the corresponding memory available (though <code><font color="blue">thread_alloc</font></code>)
to the current thread.
</li><li>

Available memory
can then be completely freed using <a href="ta_free_available.xml" target="_top"><span style='white-space: nowrap'>free_available</span></a>
.
</li></ol>


<br/>
<br/>
<b><big><a name="Example" id="Example">Example</a></big></b>

<br/>
The files
<a href="cppad_vector.cpp.xml" target="_top"><span style='white-space: nowrap'>cppad_vector.cpp</span></a>
 and
<a href="vector_bool.cpp.xml" target="_top"><span style='white-space: nowrap'>vector_bool.cpp</span></a>
 each
contain an example and test of this template class.
They return true if they succeed and false otherwise.

<br/>
<br/>
<b><big><a name="Exercise" id="Exercise">Exercise</a></big></b>

<br/>
Create and run a program that contains the following code:
<code><font color='blue'><pre style='display:inline'> 
	CppAD::vector&lt;double&gt; x(3);
	size_t i;
	for(i = 0; i &lt; 3; i++)
		x[i] = 4. - i;
	std::cout &lt;&lt; &quot;x = &quot; &lt;&lt; x &lt;&lt; std::endl;
</pre></font></code>



<hr/>Input File: cppad/vector.hpp

</body>
</html>
