1 /*-----------------------------------------------------------------------------+
2 Copyright (c) 2010-2011: 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_INFINITY_HPP_JOFA_100322
9 #define BOOST_ICL_TYPE_TRAITS_INFINITY_HPP_JOFA_100322
12 #include <boost/static_assert.hpp>
13 #include <boost/icl/type_traits/is_numeric.hpp>
14 #include <boost/icl/type_traits/rep_type_of.hpp>
15 #include <boost/icl/type_traits/size_type_of.hpp>
16 #include <boost/mpl/and.hpp>
17 #include <boost/mpl/if.hpp>
19 namespace boost{ namespace icl
22 template<class Type> struct has_std_infinity
24 typedef has_std_infinity type;
25 BOOST_STATIC_CONSTANT(bool,
26 value = ( is_numeric<Type>::value
27 && std::numeric_limits<Type>::has_infinity
32 template<class Type> struct has_max_infinity
34 typedef has_max_infinity type;
35 BOOST_STATIC_CONSTANT(bool,
36 value = ( is_numeric<Type>::value
37 && ! std::numeric_limits<Type>::has_infinity
42 //------------------------------------------------------------------------------
43 template <class Type, bool has_std_inf=false, bool has_std_max=false>
44 struct get_numeric_infinity;
46 template <class Type, bool has_std_max>
47 struct get_numeric_infinity<Type, true, has_std_max>
49 typedef get_numeric_infinity type;
52 return (std::numeric_limits<Type>::infinity)();
57 struct get_numeric_infinity<Type, false, true>
59 typedef get_numeric_infinity type;
62 return (std::numeric_limits<Type>::max)();
67 struct get_numeric_infinity<Type, false, false>
69 typedef get_numeric_infinity type;
77 struct numeric_infinity
79 typedef numeric_infinity type;
82 return get_numeric_infinity< Type
83 , has_std_infinity<Type>::value
84 , has_max_infinity<Type>::value >::value();
89 //------------------------------------------------------------------------------
90 template<class Type, bool has_numeric_inf, bool has_repr_inf, bool has_size, bool has_diff>
93 template<class Type, bool has_repr_inf, bool has_size, bool has_diff>
94 struct get_infinity<Type, true, has_repr_inf, has_size, has_diff>
96 typedef get_infinity type;
100 return numeric_infinity<Type>::value();
104 template<class Type, bool has_size, bool has_diff>
105 struct get_infinity<Type, false, true, has_size, has_diff>
107 typedef get_infinity type;
111 return Type(numeric_infinity<typename Type::rep>::value());
115 template<class Type, bool has_diff>
116 struct get_infinity<Type, false, false, true, has_diff>
118 typedef get_infinity type;
119 typedef typename Type::size_type size_type;
123 return Type(numeric_infinity<size_type>::value());
128 struct get_infinity<Type, false, false, false, true>
130 typedef get_infinity type;
131 typedef typename Type::difference_type difference_type;
135 return identity_element<difference_type>::value();
140 struct get_infinity<Type, false, false, false, false>
142 typedef get_infinity type;
146 return identity_element<Type>::value();
150 template <class Type> struct infinity
152 typedef infinity type;
158 , is_numeric<Type>::value
159 , has_rep_type<Type>::value
160 , has_size_type<Type>::value
161 , has_difference_type<Type>::value
167 struct infinity<std::string>
169 typedef infinity type;
171 static std::string value()
173 return std::string();
177 }} // namespace boost icl