<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>Simple Vector Template Class: Example and Test</title>
<meta name="description" id="description" content="Simple Vector Template Class: Example and Test"/>
<meta name="keywords" id="keywords" content=" vector simple example test "/>
<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='_simple_vector.cpp_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="simplevector.xml" target="_top">Prev</a>
</td><td><a href="checksimplevector.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>SimpleVector</option>
<option>simple_vector.cpp</option>
</select>
</td>
<td>
<select onchange='choose_down3(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_down2(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_down1(this)'>
<option>SimpleVector-&gt;</option>
<option>simple_vector.cpp</option>
</select>
</td>
<td>simple_vector.cpp</td>
<td>Headings</td>
</tr></table><br/>



<center><b><big><big>Simple Vector Template Class: Example and Test</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 
# include &lt;iostream&gt;                   // std::cout and std::endl

# include &lt;vector&gt;                     // std::vector
# include &lt;valarray&gt;                   // std::valarray
# include &lt;cppad/vector.hpp&gt;       // CppAD::vector
# include &lt;cppad/check_simple_vector.hpp&gt;  // CppAD::CheckSimpleVector
namespace {
	template &lt;typename Vector&gt;
	bool Ok(void)
	{	// type corresponding to elements of Vector
		typedef typename Vector::value_type Scalar;

		bool ok = true;             // initialize testing flag

		Vector x;                   // use the default constructor
		ok &amp;= (x.size() == 0);      // test size for an empty vector
		Vector y(2);                // use the sizing constructor
		ok &amp;= (y.size() == 2);      // size for an vector with elements

		// non-const access to the elements of y
		size_t i;                   
		for(i = 0; i &lt; 2; i++)
			y[i] = Scalar(i); 

		const Vector z(y);          // copy constructor
		x.resize(2);                // resize 
		x = z;                      // vector assignment

		// use the const access to the elements of x
		// and test the values of elements of x, y, z
		for(i = 0; i &lt; 2; i++)
		{	ok &amp;= (x[i] == Scalar(i));
			ok &amp;= (y[i] == Scalar(i));
			ok &amp;= (z[i] == Scalar(i));
		}
		return ok;
	}
}
bool SimpleVector (void)
{	bool ok = true;

	// use routine above to check these cases
	ok &amp;= Ok&lt; std::vector&lt;double&gt; &gt;();
	ok &amp;= Ok&lt; std::valarray&lt;float&gt; &gt;();
	ok &amp;= Ok&lt; CppAD::vector&lt;int&gt; &gt;();
# ifndef _MSC_VER
	// Avoid Microsoft following compiler warning:  'size_t' : 
	// forcing value to bool 'true' or 'false' (performance warning) 
	ok &amp;= Ok&lt; std::vector&lt;bool&gt; &gt;();
	ok &amp;= Ok&lt; CppAD::vector&lt;bool&gt; &gt;();
# endif
	// use CheckSimpleVector for more extensive testing
	CppAD::CheckSimpleVector&lt;double, std::vector&lt;double&gt;  &gt;();
	CppAD::CheckSimpleVector&lt;float,  std::valarray&lt;float&gt; &gt;();
	CppAD::CheckSimpleVector&lt;int,    CppAD::vector&lt;int&gt;   &gt;();
	CppAD::CheckSimpleVector&lt;bool,   std::vector&lt;bool&gt;    &gt;();
	CppAD::CheckSimpleVector&lt;bool,   CppAD::vector&lt;bool&gt;  &gt;();

	return ok;
}
</pre>

</font></code>


<hr/>Input File: example/simple_vector.cpp

</body>
</html>
