sl@0: // boost integer.hpp header file -------------------------------------------// sl@0: sl@0: // Copyright Beman Dawes and Daryle Walker 1999. Distributed under the Boost sl@0: // Software License, Version 1.0. (See accompanying file sl@0: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) sl@0: sl@0: // See http://www.boost.org/libs/integer for documentation. sl@0: sl@0: // Revision History sl@0: // 22 Sep 01 Added value-based integer templates. (Daryle Walker) sl@0: // 01 Apr 01 Modified to use new header. (John Maddock) sl@0: // 30 Jul 00 Add typename syntax fix (Jens Maurer) sl@0: // 28 Aug 99 Initial version sl@0: sl@0: #ifndef BOOST_INTEGER_HPP sl@0: #define BOOST_INTEGER_HPP sl@0: sl@0: #include // self include sl@0: sl@0: #include // for boost::integer_traits sl@0: #include // for std::numeric_limits sl@0: sl@0: namespace boost sl@0: { sl@0: sl@0: // Helper templates ------------------------------------------------------// sl@0: sl@0: // fast integers from least integers sl@0: // int_fast_t<> works correctly for unsigned too, in spite of the name. sl@0: template< typename LeastInt > sl@0: struct int_fast_t { typedef LeastInt fast; }; // imps may specialize sl@0: sl@0: // convert category to type sl@0: template< int Category > struct int_least_helper {}; // default is empty sl@0: sl@0: // specializatons: 1=long, 2=int, 3=short, 4=signed char, sl@0: // 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned long sl@0: // no specializations for 0 and 5: requests for a type > long are in error sl@0: template<> struct int_least_helper<1> { typedef long least; }; sl@0: template<> struct int_least_helper<2> { typedef int least; }; sl@0: template<> struct int_least_helper<3> { typedef short least; }; sl@0: template<> struct int_least_helper<4> { typedef signed char least; }; sl@0: template<> struct int_least_helper<6> { typedef unsigned long least; }; sl@0: template<> struct int_least_helper<7> { typedef unsigned int least; }; sl@0: template<> struct int_least_helper<8> { typedef unsigned short least; }; sl@0: template<> struct int_least_helper<9> { typedef unsigned char least; }; sl@0: sl@0: // integer templates specifying number of bits ---------------------------// sl@0: sl@0: // signed sl@0: template< int Bits > // bits (including sign) required sl@0: struct int_t sl@0: { sl@0: typedef typename int_least_helper sl@0: < sl@0: (Bits-1 <= std::numeric_limits::digits) + sl@0: (Bits-1 <= std::numeric_limits::digits) + sl@0: (Bits-1 <= std::numeric_limits::digits) + sl@0: (Bits-1 <= std::numeric_limits::digits) sl@0: >::least least; sl@0: typedef typename int_fast_t::fast fast; sl@0: }; sl@0: sl@0: // unsigned sl@0: template< int Bits > // bits required sl@0: struct uint_t sl@0: { sl@0: typedef typename int_least_helper sl@0: < sl@0: 5 + sl@0: (Bits <= std::numeric_limits::digits) + sl@0: (Bits <= std::numeric_limits::digits) + sl@0: (Bits <= std::numeric_limits::digits) + sl@0: (Bits <= std::numeric_limits::digits) sl@0: >::least least; sl@0: typedef typename int_fast_t::fast fast; sl@0: // int_fast_t<> works correctly for unsigned too, in spite of the name. sl@0: }; sl@0: sl@0: // integer templates specifying extreme value ----------------------------// sl@0: sl@0: // signed sl@0: template< long MaxValue > // maximum value to require support sl@0: struct int_max_value_t sl@0: { sl@0: typedef typename int_least_helper sl@0: < sl@0: (MaxValue <= integer_traits::const_max) + sl@0: (MaxValue <= integer_traits::const_max) + sl@0: (MaxValue <= integer_traits::const_max) + sl@0: (MaxValue <= integer_traits::const_max) sl@0: >::least least; sl@0: typedef typename int_fast_t::fast fast; sl@0: }; sl@0: sl@0: template< long MinValue > // minimum value to require support sl@0: struct int_min_value_t sl@0: { sl@0: typedef typename int_least_helper sl@0: < sl@0: (MinValue >= integer_traits::const_min) + sl@0: (MinValue >= integer_traits::const_min) + sl@0: (MinValue >= integer_traits::const_min) + sl@0: (MinValue >= integer_traits::const_min) sl@0: >::least least; sl@0: typedef typename int_fast_t::fast fast; sl@0: }; sl@0: sl@0: // unsigned sl@0: template< unsigned long Value > // maximum value to require support sl@0: struct uint_value_t sl@0: { sl@0: typedef typename int_least_helper sl@0: < sl@0: 5 + sl@0: (Value <= integer_traits::const_max) + sl@0: (Value <= integer_traits::const_max) + sl@0: (Value <= integer_traits::const_max) + sl@0: (Value <= integer_traits::const_max) sl@0: >::least least; sl@0: typedef typename int_fast_t::fast fast; sl@0: }; sl@0: sl@0: sl@0: } // namespace boost sl@0: sl@0: #endif // BOOST_INTEGER_HPP