CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ad_assign.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_CORE_AD_ASSIGN_HPP
2 # define CPPAD_CORE_AD_ASSIGN_HPP
3 
4 /* --------------------------------------------------------------------------
5 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
6 
7 CppAD is distributed under multiple licenses. This distribution is under
8 the terms of the
9  Eclipse Public License Version 1.0.
10 
11 A copy of this license is included in the COPYING file of this distribution.
12 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
13 -------------------------------------------------------------------------- */
14 
15 /*
16 ------------------------------------------------------------------------------
17 
18 $begin ad_assign$$
19 $spell
20  Vec
21  const
22 $$
23 
24 
25 $section AD Assignment Operator$$
26 $mindex assign Base VecAD$$
27 
28 $head Syntax$$
29 $icode%y% = %x%$$
30 
31 $head Purpose$$
32 Assigns the value in $icode x$$ to the object $icode y$$.
33 In either case,
34 
35 $head x$$
36 The argument $icode x$$ has prototype
37 $codei%
38  const %Type% &%x%
39 %$$
40 where $icode Type$$ is
41 $codei%VecAD<%Base%>::reference%$$,
42 $codei%AD<%Base%>%$$,
43 $icode Base$$,
44 or any type that has an implicit constructor of the form
45 $icode%Base%(%x%)%$$.
46 
47 $head y$$
48 The target $icode y$$ has prototype
49 $codei%
50  AD<%Base%> %y%
51 %$$
52 
53 $head Example$$
54 $children%
55  example/general/ad_assign.cpp
56 %$$
57 The file $cref ad_assign.cpp$$ contain examples and tests of these operations.
58 It test returns true if it succeeds and false otherwise.
59 
60 $end
61 ------------------------------------------------------------------------------
62 */
63 
64 namespace CppAD { // BEGIN_CPPAD_NAMESPACE
65 
66 /*!
67 \file ad_assign.hpp
68 AD<Base> constructors and and copy operations.
69 */
70 
71 /*!
72 \page AD_default_assign
73 Use default assignment operator
74 because they may be optimized better than the code below:
75 \code
76 template <class Base>
77 inline AD<Base>& AD<Base>::operator=(const AD<Base> &right)
78 { value_ = right.value_;
79  tape_id_ = right.tape_id_;
80  taddr_ = right.taddr_;
81 
82  return *this;
83 }
84 \endcode
85 */
86 
87 /*!
88 Assignment to Base type value.
89 
90 \tparam Base
91 Base type for this AD object.
92 
93 \param b
94 is the Base type value being assignment to this AD object.
95 The tape identifier will be an invalid tape identifier,
96 so this object is initially a parameter.
97 */
98 template <class Base>
99 inline AD<Base>& AD<Base>::operator=(const Base &b)
100 { value_ = b;
101  tape_id_ = 0;
102 
103  // check that this is a parameter
105 
106  return *this;
107 }
108 
109 /*!
110 Assignment to an ADVec<Base> element drops the vector information.
111 
112 \tparam Base
113 Base type for this AD object.
114 */
115 template <class Base>
117 { return *this = x.ADBase(); }
118 
119 /*!
120 Assignment from any other type, converts to Base type, and then uses assignment
121 from Base type.
122 
123 \tparam Base
124 Base type for this AD object.
125 
126 \tparam T
127 is the the type that is being assigned to AD<Base>.
128 There must be an assignment for Base from Type.
129 
130 \param t
131 is the object that is being assigned to an AD<Base> object.
132 */
133 template <class Base>
134 template <class T>
135 inline AD<Base>& AD<Base>::operator=(const T &t)
136 { return *this = Base(t); }
137 
138 
139 } // END_CPPAD_NAMESPACE
140 # endif
Definition: ad.hpp:34
AD & operator=(const Base &b)
Assignment to Base type value.
Definition: ad_assign.hpp:99
AD< Base > ADBase(void) const
Conversion from VecAD_reference to AD&lt;Base&gt;. puts the correspond vecad load instruction in the tape...
Definition: vec_ad.hpp:392
#define CPPAD_ASSERT_UNKNOWN(exp)
Check that exp is true, if not terminate execution.
Class used to hold a reference to an element of a VecAD object.
Definition: vec_ad.hpp:352
CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION bool Parameter(const AD< Base > &x)
Definition: par_var.hpp:80