CppAD: A C++ Algorithmic Differentiation Package  20130918
ad_assign.hpp
Go to the documentation of this file.
00001 /* $Id$ */
00002 # ifndef CPPAD_AD_ASSIGN_INCLUDED
00003 # define CPPAD_AD_ASSIGN_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_assign$$
00020 $spell
00021      Vec
00022      const
00023 $$
00024 
00025 $index assignment, AD$$
00026 $index AD, assignment$$
00027 $index assign, to AD$$
00028 $index Base, assign to AD$$
00029 $index VecAD, assign to AD$$
00030 
00031 $section AD Assignment Operator$$
00032 
00033 $head Syntax$$
00034 $icode%y% = %x%$$
00035 
00036 $head Purpose$$
00037 Assigns the value in $icode x$$ to the object $icode y$$.
00038 In either case, 
00039 
00040 $head x$$
00041 The argument $icode x$$ has prototype
00042 $codei%
00043      const %Type% &%x%
00044 %$$ 
00045 where $icode Type$$ is
00046 $codei%VecAD<%Base%>::reference%$$,
00047 $codei%AD<%Base%>%$$,
00048 $icode Base$$, 
00049 or any type that has a constructor of the form
00050 $icode%Base%(%x%)%$$.
00051 
00052 $head y$$
00053 The target $icode y$$ has prototype
00054 $codei%
00055      AD<%Base%> %y%
00056 %$$
00057 
00058 $head Example$$
00059 $children%
00060      example/ad_assign.cpp
00061 %$$
00062 The file $cref ad_assign.cpp$$ contain examples and tests of these operations.
00063 It test returns true if it succeeds and false otherwise.
00064 
00065 $end
00066 ------------------------------------------------------------------------------
00067 */
00068 
00069 namespace CppAD { // BEGIN_CPPAD_NAMESPACE
00070 
00071 /*!
00072 \file ad_assign.hpp
00073 AD<Base> constructors and and copy operations.
00074 */
00075 
00076 /*!
00077 \page AD_default_assign
00078 Use default assignment operator
00079 because they may be optimized better than the code below:
00080 \code
00081 template <class Base>
00082 inline AD<Base>& AD<Base>::operator=(const AD<Base> &right)
00083 {    value_    = right.value_;
00084      tape_id_  = right.tape_id_;
00085      taddr_    = right.taddr_;
00086 
00087      return *this;
00088 }
00089 \endcode
00090 */
00091 
00092 /*!
00093 Assignment to Base type value.
00094 
00095 \tparam Base
00096 Base type for this AD object.
00097 
00098 \param b
00099 is the Base type value being assignment to this AD object.
00100 The tape identifier will be an invalid tape identifier,
00101 so this object is initially a parameter.
00102 */
00103 template <class Base>
00104 inline AD<Base>& AD<Base>::operator=(const Base &b)
00105 {    value_   = b;
00106      tape_id_ = 0;
00107 
00108      // check that this is a parameter
00109      CPPAD_ASSERT_UNKNOWN( Parameter(*this) );
00110 
00111      return *this;
00112 }
00113 
00114 /*!
00115 Assignment to an ADVec<Base> element drops the vector information.
00116 
00117 \tparam Base
00118 Base type for this AD object.
00119 */
00120 template <class Base>
00121 inline AD<Base>& AD<Base>::operator=(const VecAD_reference<Base> &x)
00122 {    return *this = x.ADBase(); }
00123 
00124 /*!
00125 Assignment from any other type, converts to Base type, and then uses assignment
00126 from Base type.
00127 
00128 \tparam Base
00129 Base type for this AD object.
00130 
00131 \tparam T
00132 is the the type that is being assigned to AD<Base>.
00133 There must be an assignment for Base from Type.
00134 
00135 \param t
00136 is the object that is being assigned to an AD<Base> object.
00137 */
00138 template <class Base>
00139 template <class T>
00140 inline AD<Base>& AD<Base>::operator=(const T &t)
00141 {    return *this = Base(t); }
00142 
00143 
00144 } // END_CPPAD_NAMESPACE
00145 # endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines