std_integer_traits.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. ///////////////////////////////////////////////////////////////
  2. // Copyright 2012-2022 John Maddock.
  3. // Copyright 2022 Matt Borland. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
  6. #ifndef BOOST_MP_STD_INTEGER_TRAITS_HPP
  7. #define BOOST_MP_STD_INTEGER_TRAITS_HPP
  8. #include <type_traits>
  9. #include <boost/multiprecision/detail/standalone_config.hpp>
  10. namespace boost {
  11. namespace multiprecision {
  12. namespace detail {
  13. template <class T>
  14. struct is_signed : public std::is_signed<T> {};
  15. template <class T>
  16. struct is_unsigned : public std::is_unsigned<T> {};
  17. template <class T>
  18. struct is_integral : public std::is_integral<T> {};
  19. template <class T>
  20. struct is_arithmetic : public std::is_arithmetic<T> {};
  21. template <class T>
  22. struct make_unsigned : public std::make_unsigned<T> {};
  23. template <class T>
  24. struct make_signed : public std::make_signed<T> {};
  25. #ifdef BOOST_HAS_INT128
  26. template <>
  27. struct is_signed<int128_type> : public std::true_type {};
  28. template <>
  29. struct is_signed<uint128_type> : public std::false_type {};
  30. template <>
  31. struct is_unsigned<int128_type> : public std::false_type {};
  32. template <>
  33. struct is_unsigned<uint128_type> : public std::true_type {};
  34. template <>
  35. struct is_integral<int128_type> : public std::true_type {};
  36. template <>
  37. struct is_integral<uint128_type> : public std::true_type {};
  38. template <>
  39. struct is_arithmetic<int128_type> : public std::true_type {};
  40. template <>
  41. struct is_arithmetic<uint128_type> : public std::true_type {};
  42. template <>
  43. struct make_unsigned<int128_type>
  44. {
  45. using type = uint128_type;
  46. };
  47. template <>
  48. struct make_unsigned<uint128_type>
  49. {
  50. using type = uint128_type;
  51. };
  52. template <>
  53. struct make_signed<int128_type>
  54. {
  55. using type = int128_type;
  56. };
  57. template <>
  58. struct make_signed<uint128_type>
  59. {
  60. using type = int128_type;
  61. };
  62. #endif
  63. // C++17-esque helpers
  64. #if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304L
  65. template <typename T>
  66. BOOST_INLINE_CONSTEXPR bool is_signed_v = is_signed<T>::value;
  67. template <typename T>
  68. BOOST_INLINE_CONSTEXPR bool is_unsigned_v = is_unsigned<T>::value;
  69. template <typename T>
  70. BOOST_INLINE_CONSTEXPR bool is_integral_v = is_integral<T>::value;
  71. template <typename T>
  72. BOOST_INLINE_CONSTEXPR bool is_arithmetic_v = is_arithmetic<T>::value;
  73. #endif
  74. template <typename T>
  75. using make_unsigned_t = typename make_unsigned<T>::type;
  76. template <typename T>
  77. using make_signed_t = typename make_signed<T>::type;
  78. }}} // namespace boost::multiprecision::detail
  79. #endif