Skip to content

Commit

Permalink
Only allow fvar constructor for convertible types
Browse files Browse the repository at this point in the history
Only test quadrature


constexpr if compatibility macro


typo


Fix derivative casting?


different way


boost::has_right_shift fails for me even before fvar changes...


prep for PR


cleaning
  • Loading branch information
wgledbetter committed Aug 26, 2020
1 parent d721493 commit 32c7768
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions include/boost/math/differentiation/autodiff.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ class fvar {
// RealType(ca) | RealType | RealType is copy constructible from the arithmetic types.
explicit fvar(root_type const&); // Initialize a constant. (No epsilon terms.)

template <typename RealType2>
template <typename RealType2, typename std::enable_if<std::is_convertible<RealType2, RealType>::value>::type* = nullptr>
fvar(RealType2 const& ca); // Supports any RealType2 for which static_cast<root_type>(ca) compiles.

// r = cr | RealType& | Assignment operator.
fvar& operator=(fvar const&) = default;

// r = ca | RealType& | Assignment operator from the arithmetic types.
// Handled by constructor that takes a single parameter of generic type.
// fvar& operator=(root_type const&); // Set a constant.
template<typename RealType2>
typename std::enable_if<std::is_convertible<RealType2, RealType>::value, fvar&>::type& operator=(RealType2 const&);

// r += cr | RealType& | Adds cr to r.
template <typename RealType2, size_t Order2>
Expand Down Expand Up @@ -678,19 +678,18 @@ fvar<RealType, Order>::fvar(root_type const& ca) : v{{static_cast<RealType>(ca)}

// Can cause compiler error if RealType2 cannot be cast to root_type.
template <typename RealType, size_t Order>
template <typename RealType2>
template <typename RealType2, typename std::enable_if<std::is_convertible<RealType2, RealType>::value>::type*>
fvar<RealType, Order>::fvar(RealType2 const& ca) : v{{static_cast<RealType>(ca)}} {}

/*
template<typename RealType, size_t Order>
fvar<RealType,Order>& fvar<RealType,Order>::operator=(root_type const& ca)
template<typename RealType2>
typename std::enable_if<std::is_convertible<RealType2, RealType>::value, fvar<RealType, Order>&>::type& fvar<RealType,Order>::operator=(RealType2 const& ca)
{
v.front() = static_cast<RealType>(ca);
if constexpr (0 < Order)
BOOST_IF_CONSTEXPR (0 < Order)
std::fill(v.begin()+1, v.end(), static_cast<RealType>(0));
return *this;
}
*/

template <typename RealType, size_t Order>
template <typename RealType2, size_t Order2>
Expand Down

0 comments on commit 32c7768

Please sign in to comment.