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 
6 #if !defined(BOOST_SPIRIT_NUMERIC_TRAITS_JAN_07_2011_0722AM)
7 #define BOOST_SPIRIT_NUMERIC_TRAITS_JAN_07_2011_0722AM
8 
9 #if defined(_MSC_VER)
10 #pragma once
11 #endif
12 
13 #include <boost/config.hpp>
14 #include <boost/mpl/bool.hpp>
15 #include <boost/integer_traits.hpp>
16 #include <boost/utility/enable_if.hpp>
17 
18 namespace boost { namespace spirit { namespace traits
19 {
20     ///////////////////////////////////////////////////////////////////////////
21     // Determine if T is a boolean type
22     ///////////////////////////////////////////////////////////////////////////
23     template <typename T>
24     struct is_bool : mpl::false_ {};
25 
26     template <typename T>
27     struct is_bool<T const> : is_bool<T> {};
28 
29     template <>
30     struct is_bool<bool> : mpl::true_ {};
31 
32     ///////////////////////////////////////////////////////////////////////////
33     // Determine if T is a signed integer type
34     ///////////////////////////////////////////////////////////////////////////
35     template <typename T>
36     struct is_int : mpl::false_ {};
37 
38     template <typename T>
39     struct is_int<T const> : is_int<T> {};
40 
41     template <>
42     struct is_int<short> : mpl::true_ {};
43 
44     template <>
45     struct is_int<int> : mpl::true_ {};
46 
47     template <>
48     struct is_int<long> : mpl::true_ {};
49 
50 #ifdef BOOST_HAS_LONG_LONG
51     template <>
52     struct is_int<boost::long_long_type> : mpl::true_ {};
53 #endif
54 
55     ///////////////////////////////////////////////////////////////////////////
56     // Determine if T is an unsigned integer type
57     ///////////////////////////////////////////////////////////////////////////
58     template <typename T>
59     struct is_uint : mpl::false_ {};
60 
61     template <typename T>
62     struct is_uint<T const> : is_uint<T> {};
63 
64 #if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
65     template <>
66     struct is_uint<unsigned short> : mpl::true_ {};
67 #endif
68 
69     template <>
70     struct is_uint<unsigned int> : mpl::true_ {};
71 
72     template <>
73     struct is_uint<unsigned long> : mpl::true_ {};
74 
75 #ifdef BOOST_HAS_LONG_LONG
76     template <>
77     struct is_uint<boost::ulong_long_type> : mpl::true_ {};
78 #endif
79 
80     ///////////////////////////////////////////////////////////////////////////
81     // Determine if T is a floating point type
82     ///////////////////////////////////////////////////////////////////////////
83     template <typename T>
84     struct is_real : mpl::false_ {};
85 
86     template <typename T>
87     struct is_real<T const> : is_uint<T> {};
88 
89     template <>
90     struct is_real<float> : mpl::true_ {};
91 
92     template <>
93     struct is_real<double> : mpl::true_ {};
94 
95     template <>
96     struct is_real<long double> : mpl::true_ {};
97 
98     ///////////////////////////////////////////////////////////////////////////
99     // customization points for numeric operations
100     ///////////////////////////////////////////////////////////////////////////
101     template <typename T, typename Enable = void>
102     struct absolute_value;
103 
104     template <typename T, typename Enable = void>
105     struct is_negative;
106 
107     template <typename T, typename Enable = void>
108     struct is_zero;
109 
110     template <typename T, typename Enable = void>
111     struct pow10_helper;
112 
113     template <typename T, typename Enable = void>
114     struct is_nan;
115 
116     template <typename T, typename Enable = void>
117     struct is_infinite;
118 
119     template <typename T, typename Enable = void>
120     struct check_overflow : mpl::false_ {};
121 
122     template <typename T>
123     struct check_overflow<T, typename enable_if_c<integer_traits<T>::is_integral>::type>
124         : mpl::true_ {};
125 }}}
126 
127 #endif
128