Boost logo

Boost Users :

Subject: Re: [Boost-users] deleting operators to forbid mixed arithmetic? [multiprecision]
From: John Maddock (jz.maddock_at_[hidden])
Date: 2017-08-12 17:13:54

On 12/08/2017 00:53, Dani Brake via Boost-users wrote:
> Hi,
> I'd like to forbid multiplication of Boost.Multiprecision floating
> point numbers by doubles. Any tips? I think I want to delete a
> family of operator*s, but am having a hard time coming up with which ones.

All the operators are enable_if'ed on "is_compatible_arithmetic_type<V,
M>::value" where V is the arithmetic type and M is the multiprecision
type. The trait is defined in
boost/multiprecision/detail/number_base.hpp as:

template <class T, class Num>
struct is_compatible_arithmetic_type
    : public mpl::bool_<
          is_convertible<T, Num>::value
          && !is_same<T, Num>::value
          && !is_number_expression<T>::value>

So in principle you just define a full or partial specialization, for

template <class Backend>
struct is_compatible_arithmetic_type<double, number<Backend> > : public
mpl::false_ {};

and then cross your fingers and hope for the best ;)

This is untried, and it's quite likely there will be collateral damage -
things which should compile but don't any more because they multiply by
0.5 or something.

HTH, John.

This email has been checked for viruses by AVG.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at