Skip to content

Commit

Permalink
Add copy assignment operators for T2 and DualNumber<T2,D2>
Browse files Browse the repository at this point in the history
  • Loading branch information
lindsayad committed Dec 3, 2018
1 parent 104919b commit 1a61f09
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/numerics/include/metaphysicl/dualnumber.h
Expand Up @@ -72,6 +72,17 @@ inline
DualNumber<T,D>
DualNumber<T,D>::operator! () const { return DualNumber<T,D>(!_val, !_deriv); }

template <typename T, typename D>
template <typename T2, typename D2>
inline
DualNumber<T,D> &
DualNumber<T,D>::operator=(const DualNumber<T2,D2> & dn)
{
_val = dn.value();
_deriv = dn.derivatives();
return *this;
}

template <typename T, typename D>
template <typename T2, typename D2>
inline
Expand Down Expand Up @@ -106,6 +117,17 @@ DualNumber<T,D>::operator=(const DualNumberSurrogate<T2,D2> & dns)
return *this;
}

template <typename T, typename D>
template <typename T2>
inline
DualNumber<T,D> &
DualNumber<T,D>::operator=(const T2 & scalar)
{
_val = scalar;
_deriv = 0;
return *this;
}

//
// Member function definitions
//
Expand Down
6 changes: 6 additions & 0 deletions src/numerics/include/metaphysicl/dualnumber_decl.h
Expand Up @@ -74,6 +74,9 @@ class DualNumber : public safe_bool<DualNumber<T,D> >
DualNumber& operator= (const DualNumber<T, D> & /*src*/) = default;
#endif

template <typename T2, typename D2>
DualNumber & operator=(const DualNumber<T2,D2> & dn);

template <typename T2, typename D2>
DualNumber & operator=(const NotADuckDualNumber<T2,D2> & nd_dn);

Expand All @@ -83,6 +86,9 @@ class DualNumber : public safe_bool<DualNumber<T,D> >
template <typename T2, typename D2>
DualNumber & operator= (const DualNumberSurrogate<T2, D2> & dns);

template <typename T2>
DualNumber & operator= (const T2 & scalar);

T& value();

const T& value() const;
Expand Down

0 comments on commit 1a61f09

Please sign in to comment.