Warning, file /include/boost/gil/promote_integral.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef BOOST_GIL_PROMOTE_INTEGRAL_HPP
0020 #define BOOST_GIL_PROMOTE_INTEGRAL_HPP
0021
0022 #include <boost/mp11/list.hpp>
0023
0024 #include <climits>
0025 #include <cstddef>
0026 #include <type_traits>
0027
0028 namespace boost { namespace gil
0029 {
0030
0031 namespace detail { namespace promote_integral
0032 {
0033
0034
0035 template
0036 <
0037 typename T,
0038 bool IsFundamental = std::is_fundamental<T>::value
0039 >
0040 struct bit_size {};
0041
0042
0043 template <typename T>
0044 struct bit_size<T, true> : std::integral_constant<std::size_t, (CHAR_BIT * sizeof(T))> {};
0045
0046 template
0047 <
0048 typename T,
0049 typename IntegralTypes,
0050 std::size_t MinSize
0051 >
0052 struct promote_to_larger
0053 {
0054 using current_type = boost::mp11::mp_first<IntegralTypes>;
0055 using list_after_front = boost::mp11::mp_rest<IntegralTypes>;
0056
0057 using type = typename std::conditional
0058 <
0059 (bit_size<current_type>::value >= MinSize),
0060 current_type,
0061 typename promote_to_larger
0062 <
0063 T,
0064 list_after_front,
0065 MinSize
0066 >::type
0067 >::type;
0068 };
0069
0070
0071
0072 template <typename T, std::size_t MinSize>
0073 struct promote_to_larger<T, boost::mp11::mp_list<>, MinSize>
0074 {
0075
0076
0077 using type = T;
0078 };
0079
0080 }}
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114 template
0115 <
0116 typename T,
0117 bool PromoteUnsignedToUnsigned = false,
0118 bool UseCheckedInteger = false,
0119 bool IsIntegral = std::is_integral<T>::value
0120 >
0121 class promote_integral
0122 {
0123 private:
0124 static bool const is_unsigned = std::is_unsigned<T>::value;
0125
0126 using bit_size_type = detail::promote_integral::bit_size<T>;
0127
0128
0129
0130
0131
0132
0133
0134
0135 using min_bit_size_type = typename std::conditional
0136 <
0137 (PromoteUnsignedToUnsigned && is_unsigned),
0138 std::integral_constant<std::size_t, (2 * bit_size_type::value)>,
0139 typename std::conditional
0140 <
0141 is_unsigned,
0142 std::integral_constant<std::size_t, (2 * bit_size_type::value + 1)>,
0143 std::integral_constant<std::size_t, (2 * bit_size_type::value - 1)>
0144 >::type
0145 >::type;
0146
0147
0148
0149 using signed_integral_types = boost::mp11::mp_list
0150 <
0151 short, int, long
0152 #if defined(BOOST_HAS_LONG_LONG)
0153 , boost::long_long_type
0154 #endif
0155 >;
0156
0157
0158
0159 using unsigned_integral_types = boost::mp11::mp_list
0160 <
0161 unsigned short, unsigned int, unsigned long, std::size_t
0162 #if defined(BOOST_HAS_LONG_LONG)
0163 , boost::ulong_long_type
0164 #endif
0165 >;
0166
0167
0168
0169
0170 using integral_types = typename std::conditional
0171 <
0172 (is_unsigned && PromoteUnsignedToUnsigned),
0173 unsigned_integral_types,
0174 signed_integral_types
0175 >::type;
0176
0177 public:
0178 using type = typename detail::promote_integral::promote_to_larger
0179 <
0180 T,
0181 integral_types,
0182 min_bit_size_type::value
0183 >::type;
0184 };
0185
0186
0187 template <typename T, bool PromoteUnsignedToUnsigned, bool UseCheckedInteger>
0188 class promote_integral
0189 <
0190 T, PromoteUnsignedToUnsigned, UseCheckedInteger, false
0191 >
0192 {
0193 public:
0194 using type = T;
0195 };
0196
0197 }}
0198
0199 #endif