numeric_traits.hpp 3.5 KB

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