1 /* --------------------------------------------------------------------------
2 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3
4 CppAD is distributed under the terms of the
5 Eclipse Public License Version 2.0.
6
7 This Source Code may also be made available under the following
8 Secondary License when the conditions for such availability set forth
9 in the Eclipse Public License, Version 2.0 are satisfied:
10 GNU General Public License, Version 2.0 or later.
11 ---------------------------------------------------------------------------- */
12
13 /*
14 $begin ad_ctor.cpp$$
15 $spell
16 Cpp
17 $$
18
19 $section AD Constructors: Example and Test$$
20
21
22 $srcthisfile%0%// BEGIN C++%// END C++%1%$$
23 $end
24 */
25 // BEGIN C++
26
27 # include <cppad/cppad.hpp>
28
ad_ctor(void)29 bool ad_ctor(void)
30 { bool ok = true; // initialize test result flag
31 using CppAD::AD; // so can use AD in place of CppAD::AD
32
33 // default constructor
34 AD<double> a;
35 a = 0.;
36 ok &= a == 0.;
37
38 // constructor from base type
39 AD<double> b(1.);
40 ok &= b == 1.;
41
42 // constructor from another type that converts to the base type
43 AD<double> c(2);
44 ok &= c == 2.;
45
46 // constructor from AD<Base>
47 AD<double> d(c);
48 ok &= d == 2.;
49
50 // constructor from a VecAD<Base> element
51 CppAD::VecAD<double> v(1);
52 v[0] = 3.;
53 AD<double> e( v[0] );
54 ok &= e == 3.;
55
56 return ok;
57 }
58
59 // END C++
60