annotate DEPENDENCIES/generic/include/boost/integer.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 // boost integer.hpp header file -------------------------------------------//
Chris@16 2
Chris@16 3 // Copyright Beman Dawes and Daryle Walker 1999. Distributed under the Boost
Chris@16 4 // Software License, Version 1.0. (See accompanying file
Chris@16 5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6
Chris@16 7 // See http://www.boost.org/libs/integer for documentation.
Chris@16 8
Chris@16 9 // Revision History
Chris@16 10 // 22 Sep 01 Added value-based integer templates. (Daryle Walker)
Chris@16 11 // 01 Apr 01 Modified to use new <boost/limits.hpp> header. (John Maddock)
Chris@16 12 // 30 Jul 00 Add typename syntax fix (Jens Maurer)
Chris@16 13 // 28 Aug 99 Initial version
Chris@16 14
Chris@16 15 #ifndef BOOST_INTEGER_HPP
Chris@16 16 #define BOOST_INTEGER_HPP
Chris@16 17
Chris@16 18 #include <boost/integer_fwd.hpp> // self include
Chris@16 19
Chris@16 20 #include <boost/integer_traits.hpp> // for boost::::boost::integer_traits
Chris@16 21 #include <boost/limits.hpp> // for ::std::numeric_limits
Chris@16 22 #include <boost/cstdint.hpp> // for boost::int64_t and BOOST_NO_INTEGRAL_INT64_T
Chris@16 23 #include <boost/static_assert.hpp>
Chris@16 24
Chris@16 25 //
Chris@16 26 // We simply cannot include this header on gcc without getting copious warnings of the kind:
Chris@16 27 //
Chris@16 28 // boost/integer.hpp:77:30: warning: use of C99 long long integer constant
Chris@16 29 //
Chris@16 30 // And yet there is no other reasonable implementation, so we declare this a system header
Chris@16 31 // to suppress these warnings.
Chris@16 32 //
Chris@16 33 #if defined(__GNUC__) && (__GNUC__ >= 4)
Chris@16 34 #pragma GCC system_header
Chris@16 35 #endif
Chris@16 36
Chris@16 37 namespace boost
Chris@16 38 {
Chris@16 39
Chris@16 40 // Helper templates ------------------------------------------------------//
Chris@16 41
Chris@16 42 // fast integers from least integers
Chris@16 43 // int_fast_t<> works correctly for unsigned too, in spite of the name.
Chris@16 44 template< typename LeastInt >
Chris@101 45 struct int_fast_t
Chris@101 46 {
Chris@101 47 typedef LeastInt fast;
Chris@16 48 typedef fast type;
Chris@16 49 }; // imps may specialize
Chris@16 50
Chris@16 51 namespace detail{
Chris@16 52
Chris@101 53 // convert category to type
Chris@16 54 template< int Category > struct int_least_helper {}; // default is empty
Chris@16 55 template< int Category > struct uint_least_helper {}; // default is empty
Chris@16 56
Chris@16 57 // specializatons: 1=long, 2=int, 3=short, 4=signed char,
Chris@16 58 // 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned char
Chris@16 59 // no specializations for 0 and 5: requests for a type > long are in error
Chris@16 60 #ifdef BOOST_HAS_LONG_LONG
Chris@16 61 template<> struct int_least_helper<1> { typedef boost::long_long_type least; };
Chris@16 62 #elif defined(BOOST_HAS_MS_INT64)
Chris@16 63 template<> struct int_least_helper<1> { typedef __int64 least; };
Chris@16 64 #endif
Chris@16 65 template<> struct int_least_helper<2> { typedef long least; };
Chris@16 66 template<> struct int_least_helper<3> { typedef int least; };
Chris@16 67 template<> struct int_least_helper<4> { typedef short least; };
Chris@16 68 template<> struct int_least_helper<5> { typedef signed char least; };
Chris@16 69 #ifdef BOOST_HAS_LONG_LONG
Chris@16 70 template<> struct uint_least_helper<1> { typedef boost::ulong_long_type least; };
Chris@16 71 #elif defined(BOOST_HAS_MS_INT64)
Chris@16 72 template<> struct uint_least_helper<1> { typedef unsigned __int64 least; };
Chris@16 73 #endif
Chris@16 74 template<> struct uint_least_helper<2> { typedef unsigned long least; };
Chris@16 75 template<> struct uint_least_helper<3> { typedef unsigned int least; };
Chris@16 76 template<> struct uint_least_helper<4> { typedef unsigned short least; };
Chris@16 77 template<> struct uint_least_helper<5> { typedef unsigned char least; };
Chris@16 78
Chris@16 79 template <int Bits>
Chris@16 80 struct exact_signed_base_helper{};
Chris@16 81 template <int Bits>
Chris@16 82 struct exact_unsigned_base_helper{};
Chris@16 83
Chris@16 84 template <> struct exact_signed_base_helper<sizeof(signed char)* CHAR_BIT> { typedef signed char exact; };
Chris@16 85 template <> struct exact_unsigned_base_helper<sizeof(unsigned char)* CHAR_BIT> { typedef unsigned char exact; };
Chris@16 86 #if USHRT_MAX != UCHAR_MAX
Chris@16 87 template <> struct exact_signed_base_helper<sizeof(short)* CHAR_BIT> { typedef short exact; };
Chris@16 88 template <> struct exact_unsigned_base_helper<sizeof(unsigned short)* CHAR_BIT> { typedef unsigned short exact; };
Chris@16 89 #endif
Chris@16 90 #if UINT_MAX != USHRT_MAX
Chris@16 91 template <> struct exact_signed_base_helper<sizeof(int)* CHAR_BIT> { typedef int exact; };
Chris@16 92 template <> struct exact_unsigned_base_helper<sizeof(unsigned int)* CHAR_BIT> { typedef unsigned int exact; };
Chris@16 93 #endif
Chris@101 94 #if ULONG_MAX != UINT_MAX && ( !defined __TI_COMPILER_VERSION__ || \
Chris@101 95 ( __TI_COMPILER_VERSION__ >= 7000000 && !defined __TI_40BIT_LONG__ ) )
Chris@16 96 template <> struct exact_signed_base_helper<sizeof(long)* CHAR_BIT> { typedef long exact; };
Chris@16 97 template <> struct exact_unsigned_base_helper<sizeof(unsigned long)* CHAR_BIT> { typedef unsigned long exact; };
Chris@16 98 #endif
Chris@16 99 #if defined(BOOST_HAS_LONG_LONG) &&\
Chris@16 100 ((defined(ULLONG_MAX) && (ULLONG_MAX != ULONG_MAX)) ||\
Chris@16 101 (defined(ULONG_LONG_MAX) && (ULONG_LONG_MAX != ULONG_MAX)) ||\
Chris@16 102 (defined(ULONGLONG_MAX) && (ULONGLONG_MAX != ULONG_MAX)) ||\
Chris@16 103 (defined(_ULLONG_MAX) && (_ULLONG_MAX != ULONG_MAX)))
Chris@16 104 template <> struct exact_signed_base_helper<sizeof(boost::long_long_type)* CHAR_BIT> { typedef boost::long_long_type exact; };
Chris@16 105 template <> struct exact_unsigned_base_helper<sizeof(boost::ulong_long_type)* CHAR_BIT> { typedef boost::ulong_long_type exact; };
Chris@16 106 #endif
Chris@16 107
Chris@16 108
Chris@16 109 } // namespace detail
Chris@16 110
Chris@16 111 // integer templates specifying number of bits ---------------------------//
Chris@16 112
Chris@16 113 // signed
Chris@16 114 template< int Bits > // bits (including sign) required
Chris@101 115 struct int_t : public boost::detail::exact_signed_base_helper<Bits>
Chris@16 116 {
Chris@16 117 BOOST_STATIC_ASSERT_MSG(Bits <= (int)(sizeof(boost::intmax_t) * CHAR_BIT),
Chris@16 118 "No suitable signed integer type with the requested number of bits is available.");
Chris@101 119 typedef typename boost::detail::int_least_helper
Chris@16 120 <
Chris@16 121 #ifdef BOOST_HAS_LONG_LONG
Chris@16 122 (Bits <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) +
Chris@16 123 #else
Chris@16 124 1 +
Chris@16 125 #endif
Chris@16 126 (Bits-1 <= ::std::numeric_limits<long>::digits) +
Chris@16 127 (Bits-1 <= ::std::numeric_limits<int>::digits) +
Chris@16 128 (Bits-1 <= ::std::numeric_limits<short>::digits) +
Chris@16 129 (Bits-1 <= ::std::numeric_limits<signed char>::digits)
Chris@16 130 >::least least;
Chris@16 131 typedef typename int_fast_t<least>::type fast;
Chris@16 132 };
Chris@16 133
Chris@16 134 // unsigned
Chris@16 135 template< int Bits > // bits required
Chris@101 136 struct uint_t : public boost::detail::exact_unsigned_base_helper<Bits>
Chris@16 137 {
Chris@16 138 BOOST_STATIC_ASSERT_MSG(Bits <= (int)(sizeof(boost::uintmax_t) * CHAR_BIT),
Chris@16 139 "No suitable unsigned integer type with the requested number of bits is available.");
Chris@16 140 #if (defined(__BORLANDC__) || defined(__CODEGEAR__)) && defined(BOOST_NO_INTEGRAL_INT64_T)
Chris@16 141 // It's really not clear why this workaround should be needed... shrug I guess! JM
Chris@101 142 BOOST_STATIC_CONSTANT(int, s =
Chris@16 143 6 +
Chris@16 144 (Bits <= ::std::numeric_limits<unsigned long>::digits) +
Chris@16 145 (Bits <= ::std::numeric_limits<unsigned int>::digits) +
Chris@16 146 (Bits <= ::std::numeric_limits<unsigned short>::digits) +
Chris@16 147 (Bits <= ::std::numeric_limits<unsigned char>::digits));
Chris@16 148 typedef typename detail::int_least_helper< ::boost::uint_t<Bits>::s>::least least;
Chris@16 149 #else
Chris@101 150 typedef typename boost::detail::uint_least_helper
Chris@101 151 <
Chris@16 152 #ifdef BOOST_HAS_LONG_LONG
Chris@16 153 (Bits <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) +
Chris@16 154 #else
Chris@16 155 1 +
Chris@16 156 #endif
Chris@16 157 (Bits <= ::std::numeric_limits<unsigned long>::digits) +
Chris@16 158 (Bits <= ::std::numeric_limits<unsigned int>::digits) +
Chris@16 159 (Bits <= ::std::numeric_limits<unsigned short>::digits) +
Chris@16 160 (Bits <= ::std::numeric_limits<unsigned char>::digits)
Chris@16 161 >::least least;
Chris@16 162 #endif
Chris@16 163 typedef typename int_fast_t<least>::type fast;
Chris@16 164 // int_fast_t<> works correctly for unsigned too, in spite of the name.
Chris@16 165 };
Chris@16 166
Chris@16 167 // integer templates specifying extreme value ----------------------------//
Chris@16 168
Chris@16 169 // signed
Chris@101 170 #if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && defined(BOOST_HAS_LONG_LONG)
Chris@16 171 template< boost::long_long_type MaxValue > // maximum value to require support
Chris@16 172 #else
Chris@16 173 template< long MaxValue > // maximum value to require support
Chris@16 174 #endif
Chris@101 175 struct int_max_value_t
Chris@16 176 {
Chris@101 177 typedef typename boost::detail::int_least_helper
Chris@16 178 <
Chris@101 179 #if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && defined(BOOST_HAS_LONG_LONG)
Chris@16 180 (MaxValue <= ::boost::integer_traits<boost::long_long_type>::const_max) +
Chris@16 181 #else
Chris@16 182 1 +
Chris@16 183 #endif
Chris@16 184 (MaxValue <= ::boost::integer_traits<long>::const_max) +
Chris@16 185 (MaxValue <= ::boost::integer_traits<int>::const_max) +
Chris@16 186 (MaxValue <= ::boost::integer_traits<short>::const_max) +
Chris@16 187 (MaxValue <= ::boost::integer_traits<signed char>::const_max)
Chris@16 188 >::least least;
Chris@16 189 typedef typename int_fast_t<least>::type fast;
Chris@16 190 };
Chris@16 191
Chris@101 192 #if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && defined(BOOST_HAS_LONG_LONG)
Chris@16 193 template< boost::long_long_type MinValue > // minimum value to require support
Chris@16 194 #else
Chris@16 195 template< long MinValue > // minimum value to require support
Chris@16 196 #endif
Chris@101 197 struct int_min_value_t
Chris@16 198 {
Chris@101 199 typedef typename boost::detail::int_least_helper
Chris@16 200 <
Chris@101 201 #if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && defined(BOOST_HAS_LONG_LONG)
Chris@16 202 (MinValue >= ::boost::integer_traits<boost::long_long_type>::const_min) +
Chris@16 203 #else
Chris@16 204 1 +
Chris@16 205 #endif
Chris@16 206 (MinValue >= ::boost::integer_traits<long>::const_min) +
Chris@16 207 (MinValue >= ::boost::integer_traits<int>::const_min) +
Chris@16 208 (MinValue >= ::boost::integer_traits<short>::const_min) +
Chris@16 209 (MinValue >= ::boost::integer_traits<signed char>::const_min)
Chris@16 210 >::least least;
Chris@16 211 typedef typename int_fast_t<least>::type fast;
Chris@16 212 };
Chris@16 213
Chris@16 214 // unsigned
Chris@16 215 #if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
Chris@16 216 template< boost::ulong_long_type MaxValue > // minimum value to require support
Chris@16 217 #else
Chris@16 218 template< unsigned long MaxValue > // minimum value to require support
Chris@16 219 #endif
Chris@101 220 struct uint_value_t
Chris@16 221 {
Chris@16 222 #if (defined(__BORLANDC__) || defined(__CODEGEAR__))
Chris@16 223 // It's really not clear why this workaround should be needed... shrug I guess! JM
Chris@16 224 #if defined(BOOST_NO_INTEGRAL_INT64_T)
Chris@101 225 BOOST_STATIC_CONSTANT(unsigned, which =
Chris@16 226 1 +
Chris@16 227 (MaxValue <= ::boost::integer_traits<unsigned long>::const_max) +
Chris@16 228 (MaxValue <= ::boost::integer_traits<unsigned int>::const_max) +
Chris@16 229 (MaxValue <= ::boost::integer_traits<unsigned short>::const_max) +
Chris@16 230 (MaxValue <= ::boost::integer_traits<unsigned char>::const_max));
Chris@16 231 typedef typename detail::int_least_helper< ::boost::uint_value_t<MaxValue>::which>::least least;
Chris@16 232 #else // BOOST_NO_INTEGRAL_INT64_T
Chris@101 233 BOOST_STATIC_CONSTANT(unsigned, which =
Chris@16 234 1 +
Chris@16 235 (MaxValue <= ::boost::integer_traits<boost::ulong_long_type>::const_max) +
Chris@16 236 (MaxValue <= ::boost::integer_traits<unsigned long>::const_max) +
Chris@16 237 (MaxValue <= ::boost::integer_traits<unsigned int>::const_max) +
Chris@16 238 (MaxValue <= ::boost::integer_traits<unsigned short>::const_max) +
Chris@16 239 (MaxValue <= ::boost::integer_traits<unsigned char>::const_max));
Chris@16 240 typedef typename detail::uint_least_helper< ::boost::uint_value_t<MaxValue>::which>::least least;
Chris@16 241 #endif // BOOST_NO_INTEGRAL_INT64_T
Chris@16 242 #else
Chris@101 243 typedef typename boost::detail::uint_least_helper
Chris@101 244 <
Chris@16 245 #if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
Chris@16 246 (MaxValue <= ::boost::integer_traits<boost::ulong_long_type>::const_max) +
Chris@16 247 #else
Chris@16 248 1 +
Chris@16 249 #endif
Chris@16 250 (MaxValue <= ::boost::integer_traits<unsigned long>::const_max) +
Chris@16 251 (MaxValue <= ::boost::integer_traits<unsigned int>::const_max) +
Chris@16 252 (MaxValue <= ::boost::integer_traits<unsigned short>::const_max) +
Chris@16 253 (MaxValue <= ::boost::integer_traits<unsigned char>::const_max)
Chris@16 254 >::least least;
Chris@16 255 #endif
Chris@16 256 typedef typename int_fast_t<least>::type fast;
Chris@16 257 };
Chris@16 258
Chris@16 259
Chris@16 260 } // namespace boost
Chris@16 261
Chris@16 262 #endif // BOOST_INTEGER_HPP