1 /*-----------------------------------------------------------------------------+
2 Copyright (c) 2010-2010: Joachim Faulhaber
3 +------------------------------------------------------------------------------+
4 Distributed under the Boost Software License, Version 1.0.
5 (See accompanying file LICENCE.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 +-----------------------------------------------------------------------------*/
8 #ifndef BOOST_ICL_TYPE_TRAITS_IS_NUMERIC_HPP_JOFA_100322
9 #define BOOST_ICL_TYPE_TRAITS_IS_NUMERIC_HPP_JOFA_100322
14 #include <boost/type_traits/is_floating_point.hpp>
15 #include <boost/type_traits/is_integral.hpp>
17 namespace boost{ namespace icl
20 template <class Type> struct is_fixed_numeric
22 typedef is_fixed_numeric type;
23 BOOST_STATIC_CONSTANT(bool, value = (0 < std::numeric_limits<Type>::digits));
26 template <class Type> struct is_std_numeric
28 typedef is_std_numeric type;
29 BOOST_STATIC_CONSTANT(bool,
30 value = (std::numeric_limits<Type>::is_specialized));
33 template <class Type> struct is_std_integral
35 typedef is_std_integral type;
36 BOOST_STATIC_CONSTANT(bool,
37 value = (std::numeric_limits<Type>::is_integer));
40 template <class Type> struct is_numeric
42 typedef is_numeric type;
43 BOOST_STATIC_CONSTANT(bool, value =
44 (mpl::or_< is_std_numeric<Type>
45 , boost::is_integral<Type>
46 , is_std_integral<Type> >::value) );
50 struct is_numeric<std::complex<Type> >
52 typedef is_numeric type;
53 BOOST_STATIC_CONSTANT(bool, value = true);
56 //--------------------------------------------------------------------------
57 template<class Type, class Compare, bool Enable = false>
58 struct numeric_minimum
60 static bool is_less_than(Type){ return true; }
61 static bool is_less_than_or(Type, bool){ return true; }
65 struct numeric_minimum<Type, std::less<Type>, true>
67 static bool is_less_than(Type value)
68 { return std::less<Type>()((std::numeric_limits<Type>::min)(), value); }
70 static bool is_less_than_or(Type value, bool cond)
71 { return cond || is_less_than(value); }
75 struct numeric_minimum<Type, std::greater<Type>, true>
77 static bool is_less_than(Type value)
78 { return std::greater<Type>()((std::numeric_limits<Type>::max)(), value); }
80 static bool is_less_than_or(Type value, bool cond)
81 { return cond || is_less_than(value); }
84 //--------------------------------------------------------------------------
86 struct is_non_floating_point
88 typedef is_non_floating_point type;
89 BOOST_STATIC_CONSTANT(bool, value =
90 (mpl::not_< is_floating_point<Type> >::value));
93 }} // namespace boost icl