Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:10

0001 // Copyright 2005 Alexander Nasonov.
0002 // Distributed under the Boost Software License, Version 1.0. (See
0003 // accompanying file LICENSE_1_0.txt or copy at
0004 // http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef FILE_boost_type_traits_integral_promotion_hpp_INCLUDED
0007 #define FILE_boost_type_traits_integral_promotion_hpp_INCLUDED
0008 
0009 #include <boost/config.hpp>
0010 #include <boost/type_traits/integral_constant.hpp>
0011 #include <boost/type_traits/is_const.hpp>
0012 #include <boost/type_traits/is_enum.hpp>
0013 #include <boost/type_traits/is_volatile.hpp>
0014 #include <boost/type_traits/remove_cv.hpp>
0015 
0016 namespace boost {
0017 
0018 namespace type_traits { namespace detail {
0019 
0020 // 4.5/2
0021 template <class T> struct need_promotion : public boost::is_enum<T> {};
0022 
0023 // 4.5/1
0024 template<> struct need_promotion<char              > : public true_type {};
0025 template<> struct need_promotion<signed char       > : public true_type {};
0026 template<> struct need_promotion<unsigned char     > : public true_type {};
0027 template<> struct need_promotion<signed short int  > : public true_type {};
0028 template<> struct need_promotion<unsigned short int> : public true_type {};
0029 
0030 
0031 // Specializations for non-standard types.
0032 // Type is promoted if it's smaller then int.
0033 
0034 #define BOOST_TT_AUX_PROMOTE_NONSTANDARD_TYPE(T) \
0035     template<> struct need_promotion<T>          \
0036         : public integral_constant<bool, (sizeof(T) < sizeof(int))> {};
0037 
0038 // Same set of integral types as in boost/type_traits/is_integral.hpp.
0039 // Please, keep in sync.
0040 #if (defined(BOOST_INTEL_CXX_VERSION) && defined(_MSC_VER) && (BOOST_INTEL_CXX_VERSION <= 600)) \
0041     || (defined(BOOST_BORLANDC) && (BOOST_BORLANDC == 0x600) && (_MSC_VER < 1300))
0042 // TODO: common macro for this #if. Or better yet, PP SEQ of non-standard types.
0043 BOOST_TT_AUX_PROMOTE_NONSTANDARD_TYPE(__int8          )
0044 BOOST_TT_AUX_PROMOTE_NONSTANDARD_TYPE(unsigned __int8 )
0045 BOOST_TT_AUX_PROMOTE_NONSTANDARD_TYPE(__int16         )
0046 BOOST_TT_AUX_PROMOTE_NONSTANDARD_TYPE(unsigned __int16)
0047 BOOST_TT_AUX_PROMOTE_NONSTANDARD_TYPE(__int32         )
0048 BOOST_TT_AUX_PROMOTE_NONSTANDARD_TYPE(unsigned __int32)
0049 #ifdef BOOST_BORLANDC
0050 BOOST_TT_AUX_PROMOTE_NONSTANDARD_TYPE(unsigned __int64)
0051 BOOST_TT_AUX_PROMOTE_NONSTANDARD_TYPE(         __int64)
0052 #endif
0053 #endif
0054 
0055 #if defined(BOOST_HAS_LONG_LONG)
0056 BOOST_TT_AUX_PROMOTE_NONSTANDARD_TYPE(boost::ulong_long_type)
0057 BOOST_TT_AUX_PROMOTE_NONSTANDARD_TYPE(boost::long_long_type )
0058 #elif defined(BOOST_HAS_MS_INT64)
0059 BOOST_TT_AUX_PROMOTE_NONSTANDARD_TYPE(unsigned __int64)
0060 BOOST_TT_AUX_PROMOTE_NONSTANDARD_TYPE(         __int64)
0061 #endif
0062 
0063 #undef BOOST_TT_AUX_PROMOTE_NONSTANDARD_TYPE
0064 
0065 
0066 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
0067 // 4.5/2
0068 template<> struct need_promotion<wchar_t> : public true_type {};
0069 #endif
0070 
0071 // 4.5/3 (integral bit-field) is not supported.
0072 
0073 // 4.5/4
0074 template<> struct need_promotion<bool> : public true_type {};
0075 
0076 
0077 // Get promoted type by index and cv qualifiers.
0078 
0079 template<int Index, int IsConst, int IsVolatile> struct promote_from_index;
0080 
0081 #define BOOST_TT_AUX_PROMOTE_FROM_INDEX(N,T)                                   \
0082     template<> struct promote_from_index<N,0,0> { typedef T type; };           \
0083     template<> struct promote_from_index<N,0,1> { typedef T volatile type; };  \
0084     template<> struct promote_from_index<N,1,0> { typedef T const type; };     \
0085     template<> struct promote_from_index<N,1,1> { typedef T const volatile type; };
0086 
0087 
0088 BOOST_TT_AUX_PROMOTE_FROM_INDEX(1, int          )
0089 BOOST_TT_AUX_PROMOTE_FROM_INDEX(2, unsigned int )
0090 BOOST_TT_AUX_PROMOTE_FROM_INDEX(3, long         )
0091 BOOST_TT_AUX_PROMOTE_FROM_INDEX(4, unsigned long)
0092 
0093 
0094 // WARNING: integral promotions to non-standard types
0095 // long long and __int64 are not defined by the standard.
0096 // Additional specialisations and overloads shouldn't
0097 // introduce ambiguity, though.
0098 
0099 #if defined(BOOST_HAS_LONG_LONG)
0100 BOOST_TT_AUX_PROMOTE_FROM_INDEX(5, boost::long_long_type )
0101 BOOST_TT_AUX_PROMOTE_FROM_INDEX(6, boost::ulong_long_type)
0102 #elif defined(BOOST_HAS_MS_INT64)
0103 BOOST_TT_AUX_PROMOTE_FROM_INDEX(7, __int64         )
0104 BOOST_TT_AUX_PROMOTE_FROM_INDEX(8, unsigned __int64)
0105 #endif
0106 
0107 #undef BOOST_TT_AUX_PROMOTE_FROM_INDEX
0108 
0109 
0110 // Define BOOST_TT_AUX_PROMOTED_INDEX_TESTER:
0111 #if !defined(BOOST_MSVC)
0112 
0113 template<int N>
0114 struct sized_type_for_promotion
0115 {
0116     typedef char (&type)[N];
0117 };
0118 
0119 #define BOOST_TT_AUX_PROMOTED_INDEX_TESTER(I,T) \
0120     sized_type_for_promotion<I>::type promoted_index_tester(T);
0121 
0122 #else
0123 
0124 #define BOOST_TT_AUX_PROMOTED_INDEX_TESTER(I,T) \
0125     char (&promoted_index_tester(T))[I];
0126 
0127 #endif
0128 
0129 BOOST_TT_AUX_PROMOTED_INDEX_TESTER(1, int          )
0130 BOOST_TT_AUX_PROMOTED_INDEX_TESTER(2, unsigned int )
0131 BOOST_TT_AUX_PROMOTED_INDEX_TESTER(3, long         )
0132 BOOST_TT_AUX_PROMOTED_INDEX_TESTER(4, unsigned long)
0133 
0134 #if defined(BOOST_HAS_LONG_LONG)
0135 BOOST_TT_AUX_PROMOTED_INDEX_TESTER(5, boost::long_long_type )
0136 BOOST_TT_AUX_PROMOTED_INDEX_TESTER(6, boost::ulong_long_type)
0137 #elif defined(BOOST_HAS_MS_INT64)
0138 BOOST_TT_AUX_PROMOTED_INDEX_TESTER(7, __int64         )
0139 BOOST_TT_AUX_PROMOTED_INDEX_TESTER(8, unsigned __int64)
0140 #endif
0141 
0142 #undef BOOST_TT_AUX_PROMOTED_INDEX_TESTER
0143 
0144 
0145 // Get an index of promoted type for type T.
0146 // Precondition: need_promotion<T>
0147 template<class T>
0148 struct promoted_index
0149 {
0150     static T testee; // undefined
0151     BOOST_STATIC_CONSTANT(int, value = sizeof(promoted_index_tester(+testee)) );
0152     // Unary plus promotes testee                    LOOK HERE ---> ^
0153 };
0154 
0155 template<class T>
0156 struct integral_promotion_impl
0157 {
0158     typedef BOOST_DEDUCED_TYPENAME promote_from_index<
0159         (boost::type_traits::detail::promoted_index<T>::value)
0160       , (boost::is_const<T>::value)
0161       , (boost::is_volatile<T>::value)
0162       >::type type;
0163 };
0164 
0165 template<class T, bool b> struct integral_promotion { typedef T type; };
0166 template<class T> struct integral_promotion<T, true> : public integral_promotion_impl<T>{};
0167 
0168 } }
0169 
0170 template <class T> struct integral_promotion
0171 {
0172 private:
0173    typedef boost::type_traits::detail::need_promotion<typename remove_cv<T>::type> tag_type;
0174 public:
0175    typedef typename boost::type_traits::detail::integral_promotion<T, tag_type::value>::type type;
0176 };
0177 
0178 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
0179 
0180    template <class T> using integral_promotion_t = typename integral_promotion<T>::type;
0181 
0182 #endif
0183 
0184 }
0185 
0186 #endif // #ifndef FILE_boost_type_traits_integral_promotion_hpp_INCLUDED
0187