File indexing completed on 2025-12-16 09:53:18
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_ICL_TYPE_TRAITS_INFINITY_HPP_JOFA_100322
0009 #define BOOST_ICL_TYPE_TRAITS_INFINITY_HPP_JOFA_100322
0010
0011 #include <string>
0012 #include <boost/static_assert.hpp>
0013 #include <boost/icl/type_traits/is_numeric.hpp>
0014 #include <boost/icl/type_traits/rep_type_of.hpp>
0015 #include <boost/icl/type_traits/size_type_of.hpp>
0016 #include <boost/mpl/and.hpp>
0017 #include <boost/mpl/if.hpp>
0018
0019 namespace boost{ namespace icl
0020 {
0021
0022 template<class Type> struct has_std_infinity
0023 {
0024 typedef has_std_infinity type;
0025 BOOST_STATIC_CONSTANT(bool,
0026 value = ( is_numeric<Type>::value
0027 && std::numeric_limits<Type>::has_infinity
0028 )
0029 );
0030 };
0031
0032 template<class Type> struct has_max_infinity
0033 {
0034 typedef has_max_infinity type;
0035 BOOST_STATIC_CONSTANT(bool,
0036 value = ( is_numeric<Type>::value
0037 && ! std::numeric_limits<Type>::has_infinity
0038 )
0039 );
0040 };
0041
0042
0043 template <class Type, bool has_std_inf=false, bool has_std_max=false>
0044 struct get_numeric_infinity;
0045
0046 template <class Type, bool has_std_max>
0047 struct get_numeric_infinity<Type, true, has_std_max>
0048 {
0049 typedef get_numeric_infinity type;
0050 static Type value()
0051 {
0052 return (std::numeric_limits<Type>::infinity)();
0053 }
0054 };
0055
0056 template <class Type>
0057 struct get_numeric_infinity<Type, false, true>
0058 {
0059 typedef get_numeric_infinity type;
0060 static Type value()
0061 {
0062 return (std::numeric_limits<Type>::max)();
0063 }
0064 };
0065
0066 template <class Type>
0067 struct get_numeric_infinity<Type, false, false>
0068 {
0069 typedef get_numeric_infinity type;
0070 static Type value()
0071 {
0072 return Type();
0073 }
0074 };
0075
0076 template <class Type>
0077 struct numeric_infinity
0078 {
0079 typedef numeric_infinity type;
0080 static Type value()
0081 {
0082 return get_numeric_infinity< Type
0083 , has_std_infinity<Type>::value
0084 , has_max_infinity<Type>::value >::value();
0085 }
0086 };
0087
0088
0089
0090 template<class Type, bool has_numeric_inf, bool has_repr_inf, bool has_size, bool has_diff>
0091 struct get_infinity;
0092
0093 template<class Type, bool has_repr_inf, bool has_size, bool has_diff>
0094 struct get_infinity<Type, true, has_repr_inf, has_size, has_diff>
0095 {
0096 typedef get_infinity type;
0097
0098 static Type value()
0099 {
0100 return numeric_infinity<Type>::value();
0101 }
0102 };
0103
0104 template<class Type, bool has_size, bool has_diff>
0105 struct get_infinity<Type, false, true, has_size, has_diff>
0106 {
0107 typedef get_infinity type;
0108
0109 static Type value()
0110 {
0111 return Type(numeric_infinity<typename Type::rep>::value());
0112 }
0113 };
0114
0115 template<class Type, bool has_diff>
0116 struct get_infinity<Type, false, false, true, has_diff>
0117 {
0118 typedef get_infinity type;
0119 typedef typename Type::size_type size_type;
0120
0121 static Type value()
0122 {
0123 return Type(numeric_infinity<size_type>::value());
0124 }
0125 };
0126
0127 template<class Type>
0128 struct get_infinity<Type, false, false, false, true>
0129 {
0130 typedef get_infinity type;
0131 typedef typename Type::difference_type difference_type;
0132
0133 static Type value()
0134 {
0135 return identity_element<difference_type>::value();
0136 }
0137 };
0138
0139 template<class Type>
0140 struct get_infinity<Type, false, false, false, false>
0141 {
0142 typedef get_infinity type;
0143
0144 static Type value()
0145 {
0146 return identity_element<Type>::value();
0147 }
0148 };
0149
0150 template <class Type> struct infinity
0151 {
0152 typedef infinity type;
0153
0154 static Type value()
0155 {
0156 return
0157 get_infinity< Type
0158 , is_numeric<Type>::value
0159 , has_rep_type<Type>::value
0160 , has_size_type<Type>::value
0161 , has_difference_type<Type>::value
0162 >::value();
0163 }
0164 };
0165
0166 template <>
0167 struct infinity<std::string>
0168 {
0169 typedef infinity type;
0170
0171 static std::string value()
0172 {
0173 return std::string();
0174 }
0175 };
0176
0177 }}
0178
0179 #endif
0180
0181