Boost logo

Boost :

From: Gero Peterhoff (g.peterhoff_at_[hidden])
Date: 2023-04-20 17:42:29


Hi Matt,
the ccmath functions must/could only work with std types. Is this assumption correct?

If true:
Wouldn't it make sense to do such a check for CT? This way errors can be detected early and it generally simplifies error handling.

namespace boost::math::ccmath
{
namespace detail
{
template <typename type>
inline constexpr auto foo_impl(const Type x) noexcept { return x; }
} // detail

template <typename Type>
constexpr auto foo(const Type x) noexcept
{
        BOOST_IF_CONSTEXPR (std::is_arithmetic_v<Type>)
        {
                if (BOOST_MATH_IS_CONSTANT_EVALUATED(x))
                {
                        BOOST_IF_CONSTEXPR (std::is_integral_v<Type>)
                        {
                                return detail::foo_impl(double(x));
                        }
                        else
                        {
                                return detail::foo_impl(x);
                        }
                }
                else
                {
                        using ::std::foo;
                        return foo(x);
                }
        }
        else
        {
                static_assert(boost::dependent_false_v<Type>, "foo is not supported with this type or platform");
                return 0;
        }
}
} // boost::math::ccmath

1) In particular, this approach is useful for functions that require BOOST_MATH_BIT_CAST in their implementation. To be honest, I don't like your implementations of signbit/copysign (buggy) - I'll write you something more on that.
2) The idiom "always false" (dependent_false) guarantees that static_assert is only used for Type!=is_arithmetic.


cu
Gero





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