Skip to content

Commit 2613fac

Browse files
committed
Prevent binding polynomial<U>s to the scalar operators.
1 parent 87cfd20 commit 2613fac

1 file changed

Lines changed: 5 additions & 17 deletions

File tree

include/boost/math/tools/polynomial.hpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <boost/math/tools/real_cast.hpp>
2222
#include <boost/math/special_functions/binomial.hpp>
2323
#include <boost/operators.hpp>
24+
#include <boost/type_traits/is_convertible.hpp>
2425

2526
#include <vector>
2627
#include <ostream>
@@ -377,15 +378,17 @@ class polynomial : ordered_euclidean_ring_operators< polynomial<T> >
377378
}
378379

379380
template <class U>
380-
polynomial& operator /=(const U& value)
381+
BOOST_DEDUCED_TYPENAME enable_if<boost::is_convertible<U,T>, polynomial >::type&
382+
operator /=(const U& value)
381383
{
382384
division(value);
383385
normalize();
384386
return *this;
385387
}
386388

387389
template <class U>
388-
polynomial& operator %=(const U& /*value*/)
390+
BOOST_DEDUCED_TYPENAME enable_if<boost::is_convertible<U,T>, polynomial >::type&
391+
operator %=(const U& /*value*/)
389392
{
390393
// We can always divide by a scalar, so there is no remainder:
391394
*this = zero_element(std::multiplies<polynomial>());
@@ -431,27 +434,12 @@ class polynomial : ordered_euclidean_ring_operators< polynomial<T> >
431434
return *this;
432435
}
433436

434-
template <typename U>
435-
polynomial& operator /=(const polynomial<U>& value)
436-
{
437-
*this = quotient_remainder(*this, polynomial(value)).first;
438-
return *this;
439-
}
440-
441437
polynomial& operator %=(const polynomial& value)
442438
{
443439
*this = quotient_remainder(*this, value).second;
444440
return *this;
445441
}
446442

447-
448-
template <typename U>
449-
polynomial& operator %=(const polynomial<U>& value)
450-
{
451-
*this = quotient_remainder(*this, polynomial(value)).second;
452-
return *this;
453-
}
454-
455443
template <typename U>
456444
polynomial& operator >>=(U const &n)
457445
{

0 commit comments

Comments
 (0)