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/mpl/bool.hpp>
15 #include <boost/integer_traits.hpp>
16 #include <boost/utility/enable_if.hpp>
18 namespace boost { namespace spirit { namespace traits
20 ///////////////////////////////////////////////////////////////////////////
21 // Determine if T is a boolean type
22 ///////////////////////////////////////////////////////////////////////////
24 struct is_bool : mpl::false_ {};
27 struct is_bool<T const> : is_bool<T> {};
30 struct is_bool<bool> : mpl::true_ {};
32 ///////////////////////////////////////////////////////////////////////////
33 // Determine if T is a signed integer type
34 ///////////////////////////////////////////////////////////////////////////
36 struct is_int : mpl::false_ {};
39 struct is_int<T const> : is_int<T> {};
42 struct is_int<short> : mpl::true_ {};
45 struct is_int<int> : mpl::true_ {};
48 struct is_int<long> : mpl::true_ {};
50 #ifdef BOOST_HAS_LONG_LONG
52 struct is_int<boost::long_long_type> : mpl::true_ {};
55 ///////////////////////////////////////////////////////////////////////////
56 // Determine if T is an unsigned integer type
57 ///////////////////////////////////////////////////////////////////////////
59 struct is_uint : mpl::false_ {};
62 struct is_uint<T const> : is_uint<T> {};
64 #if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
66 struct is_uint<unsigned short> : mpl::true_ {};
70 struct is_uint<unsigned int> : mpl::true_ {};
73 struct is_uint<unsigned long> : mpl::true_ {};
75 #ifdef BOOST_HAS_LONG_LONG
77 struct is_uint<boost::ulong_long_type> : mpl::true_ {};
80 ///////////////////////////////////////////////////////////////////////////
81 // Determine if T is a floating point type
82 ///////////////////////////////////////////////////////////////////////////
84 struct is_real : mpl::false_ {};
87 struct is_real<T const> : is_uint<T> {};
90 struct is_real<float> : mpl::true_ {};
93 struct is_real<double> : mpl::true_ {};
96 struct is_real<long double> : mpl::true_ {};
98 ///////////////////////////////////////////////////////////////////////////
99 // customization points for numeric operations
100 ///////////////////////////////////////////////////////////////////////////
101 template <typename T, typename Enable = void>
102 struct absolute_value;
104 template <typename T, typename Enable = void>
107 template <typename T, typename Enable = void>
110 template <typename T, typename Enable = void>
113 template <typename T, typename Enable = void>
116 template <typename T, typename Enable = void>
119 template <typename T, typename Enable = void>
120 struct check_overflow : mpl::false_ {};
122 template <typename T>
123 struct check_overflow<T, typename enable_if_c<integer_traits<T>::is_integral>::type>