Boost logo

Boost :

From: John Maddock (jz.maddock_at_[hidden])
Date: 2023-04-17 08:05:25


On 16/04/2023 19:52, Gero Peterhoff via Boost wrote:
> Hello John,
> * problem description
> The functions of boost::multiprecision are not available in std, e.g.
> template <typename type>
> Type foo(const Type x) noexcept
> {
>  return std::sin(x) * 42;
> }
>
> using A = double;
> A a = foo(A(23)); // ok
>
> using B = boost::multiprecision::cpp_bin_float_oct;
> B b = foo(B(23)); // error
>
>
>
> As a workaround you currently have to write
> template <typename Type>
> Type bar(const Type x) noexcept
> {
>  using ::std::sin;
>  using ::boost::multiprecision::sin;
>  return sin(x) * 42;
> }
>
> using A = double;
> A a = bar(A(23)); // ok
>
> using B = boost::multiprecision::cpp_bin_float_oct;
> B b = bar(B(23)); // ok
>
>
> This contradicts the template idea and is time-consuming/error-prone.
>
We are not allowed to overload anything in namespace std, so the correct
incantation for any generic code is:

template <typename Type>
Type bar(const Type x) // cannot be noexcept if used in multiprecision case
{
 Â using ::std::sin;
 Â return sin(x) * 42; // potentially found via ADL
}

John.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk