// boost numeric_promotion.hpp header file ----------------------------------------// // (C) Copyright Stephen Nutt 2003. Permission to copy, use, modify, sell // and distribute this software is granted provided this copyright // notice appears in all copies. This software is provided "as is" without // express or implied warranty, and with no claim as to its suitability for // any purpose. // See http://www.boost.org for most recent version including documentation. // Revision History // 01 Mar 03 Initial version #ifndef BOOST_NUMERIC_PROMOTION_HPP #define BOOST_NUMERIC_PROMOTION_HPP #include namespace boost { namespace numeric_promotion { template struct priority_boost { BOOST_STATIC_CONSTANT (int, boost = 0); }; template <> struct priority_boost { BOOST_STATIC_CONSTANT (int, boost = 0x10); }; template <> struct priority_boost { BOOST_STATIC_CONSTANT (int, boost = 0x10); }; template <> struct priority_boost { BOOST_STATIC_CONSTANT (int, boost = 0x10); }; template <> struct priority_boost { BOOST_STATIC_CONSTANT (int, boost = 0x20); }; template <> struct priority_boost { BOOST_STATIC_CONSTANT (int, boost = 0x20); }; template <> struct priority_boost { BOOST_STATIC_CONSTANT (int, boost = 0x30); }; template <> struct priority_boost { BOOST_STATIC_CONSTANT (int, boost = 0x30); }; template <> struct priority_boost { BOOST_STATIC_CONSTANT (int, boost = 0x40); }; template <> struct priority_boost { BOOST_STATIC_CONSTANT (int, boost = 0x40); }; template <> struct priority_boost <__int64> { BOOST_STATIC_CONSTANT (int, boost = 0x50); }; template <> struct priority_boost { BOOST_STATIC_CONSTANT (int, boost = 0x50); }; template <> struct priority_boost { BOOST_STATIC_CONSTANT (int, boost = 0x10); }; template <> struct priority_boost { BOOST_STATIC_CONSTANT (int, boost = 0x20); }; template <> struct priority_boost { BOOST_STATIC_CONSTANT (int, boost = 0x30); }; template struct unsigned_type { typedef integer_type type; }; template <> struct unsigned_type { typedef unsigned char type; }; template <> struct unsigned_type { typedef unsigned char type; }; template <> struct unsigned_type { typedef unsigned short type; }; template <> struct unsigned_type { typedef unsigned type; }; template <> struct unsigned_type { typedef unsigned long type; }; template <> struct unsigned_type <__int64> { typedef unsigned __int64 type; }; template struct make_type { template struct make_type_detail; template <> struct make_type_detail { typedef numeric_type type; }; template <> struct make_type_detail { typedef unsigned_type::type type; }; typedef make_type_detail::type type; }; template struct priority_base { BOOST_STATIC_CONSTANT (int, base = std::numeric_limits::is_integer ? 0x4000 : 0x8000); }; template struct numeric_priority : priority_base , priority_boost { BOOST_STATIC_CONSTANT (int, digits = std::numeric_limits::digits + std::numeric_limits::is_signed); BOOST_STATIC_CONSTANT (int, priority = base + digits * 256 + boost); }; template struct promote_type_base { template struct promote_type_detail; template <> struct promote_type_detail <1> { typedef type1 type; }; template <> struct promote_type_detail <2> { typedef type2 type; }; BOOST_STATIC_CONSTANT (int, promoted_type_index = numeric_promotion::numeric_priority::priority > numeric_promotion::numeric_priority::priority ? 1 : 2); typedef promote_type_detail::type winning_type; typedef promote_type_detail<3 - promoted_type_index>::type losing_type; }; template struct promote_integer_type : promote_type_base { typedef std::numeric_limits winning_limits; typedef std::numeric_limits losing_limits; BOOST_STATIC_CONSTANT (int, force_unsigned = winning_limits::is_signed && !losing_limits::is_signed && (losing_limits::digits > winning_limits::digits)); typedef make_type::type type; }; }; template struct promote_numeric_type { template struct promote_numeric_type_detail; template <> struct promote_numeric_type_detail { typedef numeric_promotion::promote_integer_type::type type; }; template <> struct promote_numeric_type_detail { typedef numeric_promotion::promote_type_base::winning_type type; }; BOOST_STATIC_CONSTANT (int, types_are_integer = std::numeric_limits::is_integer && std::numeric_limits::is_integer); typedef promote_numeric_type_detail::type type; }; }; #endif // BOOST_NUMERIC_PROMOTION_HPP