CppAD: A C++ Algorithmic Differentiation Package  20130918
ad_ctor.hpp
Go to the documentation of this file.
00001 /* $Id$ */
00002 # ifndef CPPAD_AD_CTOR_INCLUDED
00003 # define CPPAD_AD_CTOR_INCLUDED
00004 
00005 /* --------------------------------------------------------------------------
00006 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-14 Bradley M. Bell
00007 
00008 CppAD is distributed under multiple licenses. This distribution is under
00009 the terms of the 
00010                     Eclipse Public License Version 1.0.
00011 
00012 A copy of this license is included in the COPYING file of this distribution.
00013 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
00014 -------------------------------------------------------------------------- */
00015 
00016 /*
00017 ------------------------------------------------------------------------------
00018 
00019 $begin ad_ctor$$
00020 $spell
00021      cppad
00022      ctor
00023      initializes
00024      Vec
00025      const
00026 $$
00027 
00028 $index AD, constructor$$
00029 $index constructor, AD$$
00030 $index convert, to AD$$
00031 $index Base, convert to AD$$
00032 $index VecAD, convert to AD$$
00033 
00034 $section AD Constructors $$
00035 
00036 $head Syntax$$
00037 $codei%AD<%Base%> %y%()
00038 %$$
00039 $codei%AD<%Base%> %y%(%x%)
00040 %$$
00041 $codei%AD<%Base%> %y% = %x%$$
00042 
00043 $head Purpose$$
00044 creates a new $codei%AD<%Base%>%$$ object $icode y$$ 
00045 and initializes its value as equal to $icode x$$.
00046 
00047 $head x$$
00048 
00049 $subhead implicit$$
00050 There is an implicit constructor where $icode x$$ has one of the following
00051 prototypes:
00052 $codei%
00053      const %Base%&        %x%
00054      const VecAD<%Base%>& %x%
00055 %$$ 
00056 
00057 $subhead explicit$$
00058 There is an explicit constructor where $icode x$$ has prototype
00059 $codei%
00060      const %Type%&        %x%
00061 %$$ 
00062 for any type that has an explicit constructor of the form
00063 $icode%Base%(%x%)%$$.
00064 
00065 $subhead deprecated$$
00066 $index deprecated, constructor$$
00067 $index constructor, deprecated$$
00068 If you set 
00069 $cref/cppad_implicit_ctor_from_any_type
00070      /cmake
00071      /cppad_implicit_ctor_from_any_type
00072 /$$
00073 to be $code YES$$ during the install procedure,
00074 you will get an implicit constructor with prototype
00075 $codei%
00076      const %Type%&        %x%
00077 %$$ 
00078 for any type that has an explicit constructor of the form
00079 $icode%Base%(%x%)%$$.
00080 
00081 $head y$$
00082 The target $icode y$$ has prototype
00083 $codei%
00084      AD<%Base%> %y%
00085 %$$
00086 
00087 $head Example$$
00088 $children%
00089      example/ad_ctor.cpp
00090 %$$
00091 The files $cref ad_ctor.cpp$$ contain examples and tests of these operations.
00092 It test returns true if it succeeds and false otherwise.
00093 
00094 $end
00095 ------------------------------------------------------------------------------
00096 */
00097 
00098 namespace CppAD { // BEGIN_CPPAD_NAMESPACE
00099 
00100 /*!
00101 \file ad_ctor.hpp
00102 AD<Base> constructors and and copy operations.
00103 */
00104 
00105 /*!
00106 \page AD_default_ctor
00107 Use default copy constructor 
00108 because they may be optimized better than the code below:
00109 \code
00110 template <class Base>
00111 inline AD<Base>::AD(const AD &x) 
00112 {
00113      value_    = x.value_;
00114      tape_id_  = x.tape_id_;
00115      taddr_    = x.taddr_;
00116 
00117      return;
00118 }
00119 \endcode
00120 */
00121 
00122 /*!
00123 Default Constructor.
00124 
00125 \tparam Base
00126 Base type for this AD object.
00127 */
00128 template <class Base>
00129 inline AD<Base>::AD(void) 
00130 : value_()
00131 , tape_id_(0)
00132 , taddr_(0)
00133 { }
00134 
00135 
00136 /*!
00137 Constructor from Base type.
00138 
00139 \tparam Base
00140 Base type for this AD object.
00141 
00142 \param b
00143 is the Base type value corresponding to this AD object.
00144 The tape identifier will be an invalid tape identifier,
00145 so this object is initially a parameter.
00146 */
00147 template <class Base>
00148 inline AD<Base>::AD(const Base &b) 
00149 : value_(b)
00150 , tape_id_(0)
00151 , taddr_(0)
00152 {    // check that this is a parameter
00153      CPPAD_ASSERT_UNKNOWN( Parameter(*this) );
00154 }    
00155 
00156 /*!
00157 Constructor from an ADVec<Base> element drops the vector information.
00158 
00159 \tparam Base
00160 Base type for this AD object.
00161 */
00162 template <class Base>
00163 inline AD<Base>::AD(const VecAD_reference<Base> &x)
00164 {    *this = x.ADBase(); }
00165 
00166 /*!
00167 Constructor from any other type, converts to Base type, and uses constructor
00168 from Base type.
00169 
00170 \tparam Base
00171 Base type for this AD object.
00172 
00173 \tparam T
00174 is the the type that is being converted to AD<Base>.
00175 There must be a constructor for Base from Type.
00176 
00177 \param t
00178 is the object that is being converted from T to AD<Base>.
00179 */
00180 template <class Base>
00181 template <class T>
00182 inline AD<Base>::AD(const T &t) 
00183 : value_(Base(t))
00184 , tape_id_(0)
00185 , taddr_(0)
00186 { }
00187 
00188 } // END_CPPAD_NAMESPACE
00189 # endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines