numeric_traits.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Hartmut Kaiser
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(BOOST_SPIRIT_X3_NUMERIC_TRAITS_JAN_07_2011_0722AM)
  7. #define BOOST_SPIRIT_X3_NUMERIC_TRAITS_JAN_07_2011_0722AM
  8. #include <boost/config.hpp>
  9. #include <boost/mpl/bool.hpp>
  10. #include <limits>
  11. namespace boost { namespace spirit { namespace x3 { namespace traits
  12. {
  13. ///////////////////////////////////////////////////////////////////////////
  14. // Determine if T is a boolean type
  15. ///////////////////////////////////////////////////////////////////////////
  16. template <typename T>
  17. struct is_bool : mpl::false_ {};
  18. template <typename T>
  19. struct is_bool<T const> : is_bool<T> {};
  20. template <>
  21. struct is_bool<bool> : mpl::true_ {};
  22. ///////////////////////////////////////////////////////////////////////////
  23. // Determine if T is a signed integer type
  24. ///////////////////////////////////////////////////////////////////////////
  25. template <typename T>
  26. struct is_int : mpl::false_ {};
  27. template <typename T>
  28. struct is_int<T const> : is_int<T> {};
  29. template <>
  30. struct is_int<short> : mpl::true_ {};
  31. template <>
  32. struct is_int<int> : mpl::true_ {};
  33. template <>
  34. struct is_int<long> : mpl::true_ {};
  35. #ifdef BOOST_HAS_LONG_LONG
  36. template <>
  37. struct is_int<boost::long_long_type> : mpl::true_ {};
  38. #endif
  39. ///////////////////////////////////////////////////////////////////////////
  40. // Determine if T is an unsigned integer type
  41. ///////////////////////////////////////////////////////////////////////////
  42. template <typename T>
  43. struct is_uint : mpl::false_ {};
  44. template <typename T>
  45. struct is_uint<T const> : is_uint<T> {};
  46. #if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
  47. template <>
  48. struct is_uint<unsigned short> : mpl::true_ {};
  49. #endif
  50. template <>
  51. struct is_uint<unsigned int> : mpl::true_ {};
  52. template <>
  53. struct is_uint<unsigned long> : mpl::true_ {};
  54. #ifdef BOOST_HAS_LONG_LONG
  55. template <>
  56. struct is_uint<boost::ulong_long_type> : mpl::true_ {};
  57. #endif
  58. ///////////////////////////////////////////////////////////////////////////
  59. // Determine if T is a floating point type
  60. ///////////////////////////////////////////////////////////////////////////
  61. template <typename T>
  62. struct is_real : mpl::false_ {};
  63. template <typename T>
  64. struct is_real<T const> : is_uint<T> {};
  65. template <>
  66. struct is_real<float> : mpl::true_ {};
  67. template <>
  68. struct is_real<double> : mpl::true_ {};
  69. template <>
  70. struct is_real<long double> : mpl::true_ {};
  71. ///////////////////////////////////////////////////////////////////////////
  72. // customization points for numeric operations
  73. ///////////////////////////////////////////////////////////////////////////
  74. template <typename T, typename Enable = void>
  75. struct absolute_value;
  76. template <typename T, typename Enable = void>
  77. struct is_negative;
  78. template <typename T, typename Enable = void>
  79. struct is_zero;
  80. template <typename T, typename Enable = void>
  81. struct pow10_helper;
  82. template <typename T, typename Enable = void>
  83. struct is_nan;
  84. template <typename T, typename Enable = void>
  85. struct is_infinite;
  86. template <typename T, typename Enable = void>
  87. struct check_overflow : mpl::bool_<std::numeric_limits<T>::is_bounded> {};
  88. }}}}
  89. #endif