is_convertible_arithmetic.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright 2021 John Maddock. Distributed under the Boost
  3. // Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_IS_CONVERTIBLE_ARITHMETIC_HPP
  6. #define BOOST_IS_CONVERTIBLE_ARITHMETIC_HPP
  7. #include <type_traits>
  8. #include <boost/multiprecision/detail/number_base.hpp>
  9. #include <boost/multiprecision/detail/standalone_config.hpp>
  10. namespace boost { namespace multiprecision { namespace detail {
  11. template <class V, class Backend>
  12. struct is_convertible_arithmetic
  13. {
  14. static constexpr bool value = boost::multiprecision::detail::is_arithmetic<V>::value;
  15. };
  16. //
  17. // For extension types, we don't *require* interoperability,
  18. // so only enable it if we can convert the type to the backend
  19. // losslessly, ie not via conversion to a narrower type.
  20. // Note that backends with templated constructors/=operators
  21. // will not be selected here, so these need to either specialize
  22. // this trait, or provide a proper non-template constructor/=operator
  23. // for the extension types it supports.
  24. //
  25. #ifdef BOOST_HAS_FLOAT128
  26. template <class Backend>
  27. struct is_convertible_arithmetic<float128_type, Backend>
  28. {
  29. static constexpr bool value = std::is_assignable<Backend, convertible_to<float128_type>>::value;
  30. };
  31. #endif
  32. #ifdef BOOST_HAS_INT128
  33. template <class Backend>
  34. struct is_convertible_arithmetic<int128_type, Backend>
  35. {
  36. static constexpr bool value = std::is_assignable<Backend, convertible_to<int128_type>>::value;
  37. };
  38. template <class Backend>
  39. struct is_convertible_arithmetic<uint128_type, Backend>
  40. {
  41. static constexpr bool value = std::is_assignable<Backend, convertible_to<uint128_type>>::value;
  42. };
  43. #endif
  44. }}} // namespace boost::multiprecision::detail
  45. #endif // BOOST_IS_BYTE_CONTAINER_HPP