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