/*-----------------------------------------------------------------------------+ Copyright (c) 2010-2011: Joachim Faulhaber +------------------------------------------------------------------------------+ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENCE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +-----------------------------------------------------------------------------*/ #ifndef BOOST_ICL_TYPE_TRAITS_INFINITY_HPP_JOFA_100322 #define BOOST_ICL_TYPE_TRAITS_INFINITY_HPP_JOFA_100322 #include #include #include #include #include #include #include namespace boost{ namespace icl { template struct has_std_infinity { typedef has_std_infinity type; BOOST_STATIC_CONSTANT(bool, value = ( is_numeric::value && std::numeric_limits::has_infinity ) ); }; template struct has_max_infinity { typedef has_max_infinity type; BOOST_STATIC_CONSTANT(bool, value = ( is_numeric::value && ! std::numeric_limits::has_infinity ) ); }; //------------------------------------------------------------------------------ template struct get_numeric_infinity; template struct get_numeric_infinity { typedef get_numeric_infinity type; static Type value() { return (std::numeric_limits::infinity)(); } }; template struct get_numeric_infinity { typedef get_numeric_infinity type; static Type value() { return (std::numeric_limits::max)(); } }; template struct get_numeric_infinity { typedef get_numeric_infinity type; static Type value() { return Type(); } }; template struct numeric_infinity { typedef numeric_infinity type; static Type value() { return get_numeric_infinity< Type , has_std_infinity::value , has_max_infinity::value >::value(); } }; //------------------------------------------------------------------------------ template struct get_infinity; template struct get_infinity { typedef get_infinity type; static Type value() { return numeric_infinity::value(); } }; template struct get_infinity { typedef get_infinity type; static Type value() { return Type(numeric_infinity::value()); } }; template struct get_infinity { typedef get_infinity type; typedef typename Type::size_type size_type; static Type value() { return Type(numeric_infinity::value()); } }; template struct get_infinity { typedef get_infinity type; typedef typename Type::difference_type difference_type; static Type value() { return identity_element::value(); } }; template struct get_infinity { typedef get_infinity type; static Type value() { return identity_element::value(); } }; template struct infinity { typedef infinity type; static Type value() { return get_infinity< Type , is_numeric::value , has_rep_type::value , has_size_type::value , has_difference_type::value >::value(); } }; template <> struct infinity { typedef infinity type; static std::string value() { return std::string(); } }; }} // namespace boost icl #endif