# ifndef CPPAD_AD_COPY_INCLUDED # define CPPAD_AD_COPY_INCLUDED /* -------------------------------------------------------------------------- CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 Bradley M. Bell CppAD is distributed under multiple licenses. This distribution is under the terms of the Common Public License Version 1.0. A copy of this license is included in the COPYING file of this distribution. Please visit http://www.coin-or.org/CppAD/ for information on other licenses. -------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------------ $begin ad_copy$$ $spell Vec const $$ $index AD, copy$$ $index AD, assignment$$ $index constructor, AD$$ $index assignment, AD$$ $index convert, to AD$$ $index Base, convert to AD$$ $index double, convert to AD$$ $index VecAD, convert to AD$$ $section AD Copy Constructor and Assignment Operator$$ $head Syntax$$ $subhead Constructor$$ $syntax%AD<%Base%> %y%(%x%) %$$ $syntax%AD<%Base%> %y% = %x%$$ $subhead Assignment$$ $syntax%%y% = %x%$$ $head Purpose$$ The constructor creates a new $syntax%AD<%Base%>%$$ object $italic y$$ and the assignment operator uses an existing $italic y$$. In either case, $italic y$$ has the same value as $italic x$$, and the same dependence on the $cref/independent variables/glossary/Tape/Independent Variable/$$ ($italic y$$ is a $xref/glossary/Variable/variable/$$ if and only if $italic x$$ is a variable). $head x$$ The argument $italic x$$ has prototype $syntax% const %Type% &%x% %$$ where $italic Type$$ is $syntax%VecAD<%Base%>::reference%$$, $syntax%AD<%Base%>%$$, $italic Base$$, or $code double$$. $head y$$ The target $italic y$$ has prototype $syntax% AD<%Base%> &%y% %$$ $head Example$$ $children% example/copy_ad.cpp% example/copy_base.cpp% example/eq.cpp %$$ The following files contain examples and tests of these operations. Each test returns true if it succeeds and false otherwise. $table $rref CopyAD.cpp$$ $rref CopyBase.cpp$$ $rref Eq.cpp$$ $tend $end ------------------------------------------------------------------------------ */ // BEGIN CppAD namespace namespace CppAD { # if 0 // use default copy constructor and assignment operator // because they may be optimized better by the compiler template inline AD::AD(const AD &x) { value_ = x.value_; id_ = x.id_; taddr_ = x.taddr_; return; } template inline AD& AD::operator=(const AD &right) { value_ = right.value_; id_ = right.id_; taddr_ = right.taddr_; // check that all variables are parameters while tape is empty CPPAD_ASSERT_UNKNOWN( Parameter(*this) || (tape_this() != CPPAD_NULL) ); return *this; } # endif // constructor and assignment from Base type // (if id_ is 1, taddr_ is not used, set anyway to avoid compile warning) template inline AD::AD(const Base &b) : value_(b), id_(1), taddr_(0) { } template inline AD& AD::operator=(const Base &b) { value_ = b; id_ = 1; // check that this is a parameter CPPAD_ASSERT_UNKNOWN( Parameter(*this) ); return *this; } // constructor and assignment from VecAD_reference template inline AD::AD(const VecAD_reference &x) { *this = x.ADBase(); } template inline AD& AD::operator=(const VecAD_reference &x) { return *this = x.ADBase(); } // constructor and assignment from any other type // (if id_ is 1, taddr_ is not used, set anyway to avoid compile warning) template template inline AD::AD(const T &t) : value_(Base(t)), id_(1), taddr_(0) { } template template inline AD& AD::operator=(const T &t) { return *this = Base(t); } } // END CppAD namespace # endif