1 // 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)
6 #if !defined(BOOST_SPIRIT_NUMERIC_TRAITS_JAN_07_2011_0722AM)
7 #define BOOST_SPIRIT_NUMERIC_TRAITS_JAN_07_2011_0722AM
13 #include <boost/config.hpp>
14 #include <boost/limits.hpp>
15 #include <boost/mpl/bool.hpp>
17 namespace boost { namespace spirit { namespace traits
19 ///////////////////////////////////////////////////////////////////////////
20 // Determine if T is a boolean type
21 ///////////////////////////////////////////////////////////////////////////
23 struct is_bool : mpl::false_ {};
26 struct is_bool<T const> : is_bool<T> {};
29 struct is_bool<bool> : mpl::true_ {};
31 ///////////////////////////////////////////////////////////////////////////
32 // Determine if T is a signed integer type
33 ///////////////////////////////////////////////////////////////////////////
35 struct is_int : mpl::false_ {};
38 struct is_int<T const> : is_int<T> {};
41 struct is_int<short> : mpl::true_ {};
44 struct is_int<int> : mpl::true_ {};
47 struct is_int<long> : mpl::true_ {};
49 #ifdef BOOST_HAS_LONG_LONG
51 struct is_int<boost::long_long_type> : mpl::true_ {};
54 ///////////////////////////////////////////////////////////////////////////
55 // Determine if T is an unsigned integer type
56 ///////////////////////////////////////////////////////////////////////////
58 struct is_uint : mpl::false_ {};
61 struct is_uint<T const> : is_uint<T> {};
63 #if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
65 struct is_uint<unsigned short> : mpl::true_ {};
69 struct is_uint<unsigned int> : mpl::true_ {};
72 struct is_uint<unsigned long> : mpl::true_ {};
74 #ifdef BOOST_HAS_LONG_LONG
76 struct is_uint<boost::ulong_long_type> : mpl::true_ {};
79 ///////////////////////////////////////////////////////////////////////////
80 // Determine if T is a floating point type
81 ///////////////////////////////////////////////////////////////////////////
83 struct is_real : mpl::false_ {};
86 struct is_real<T const> : is_uint<T> {};
89 struct is_real<float> : mpl::true_ {};
92 struct is_real<double> : mpl::true_ {};
95 struct is_real<long double> : mpl::true_ {};
97 ///////////////////////////////////////////////////////////////////////////
98 // customization points for numeric operations
99 ///////////////////////////////////////////////////////////////////////////
100 template <typename T, typename Enable = void>
101 struct absolute_value;
103 template <typename T, typename Enable = void>
106 template <typename T, typename Enable = void>
109 template <typename T, typename Enable = void>
112 template <typename T, typename Enable = void>
115 template <typename T, typename Enable = void>
118 template <typename T, typename Enable = void>
119 struct check_overflow : mpl::bool_<std::numeric_limits<T>::is_bounded> {};