Skip to content

Commit

Permalink
Added overload of operator>> that behaves like assignment
Browse files Browse the repository at this point in the history
Quicker testing


fix travis


prep for PR
  • Loading branch information
wgledbetter committed Aug 26, 2020
1 parent 32c7768 commit 71dbd6d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions include/boost/math/differentiation/autodiff.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ class fvar {
template <typename RealType2, size_t Order2>
friend std::ostream& operator<<(std::ostream&, fvar<RealType2, Order2> const&);

template <typename RealType2, size_t Order2>
friend std::istream& operator>>(std::istream&, fvar<RealType2, Order2> &);

template <typename RealType2, size_t Order2>
friend std::wistream& operator>>(std::wistream&, fvar<RealType2, Order2> &);

// C++11 Compatibility
#ifdef BOOST_NO_CXX17_IF_CONSTEXPR
template <typename RootType>
Expand Down Expand Up @@ -1730,6 +1736,22 @@ std::ostream& operator<<(std::ostream& out, fvar<RealType, Order> const& cr) {
return out << ')';
}

template <typename RealType, size_t Order>
std::istream& operator>>(std::istream& in, fvar<RealType, Order> & cr) {
in >> cr.v.front();
BOOST_IF_CONSTEXPR (0 < Order)
std::fill(cr.v.begin()+1, cr.v.end(), static_cast<RealType>(0));
return in;
}

template <typename RealType, size_t Order>
std::wistream& operator>>(std::wistream& in, fvar<RealType, Order> & cr) {
in >> cr.v.front();
BOOST_IF_CONSTEXPR (0 < Order)
std::fill(cr.v.begin()+1, cr.v.end(), static_cast<RealType>(0));
return in;
}

// Additional functions

template <typename RealType, size_t Order>
Expand Down

0 comments on commit 71dbd6d

Please sign in to comment.