Chris@16: // Boost integer/integer_mask.hpp header file ------------------------------// Chris@16: Chris@16: // (C) Copyright Daryle Walker 2001. Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // See http://www.boost.org for updates, documentation, and revision history. Chris@16: Chris@16: #ifndef BOOST_INTEGER_INTEGER_MASK_HPP Chris@16: #define BOOST_INTEGER_INTEGER_MASK_HPP Chris@16: Chris@16: #include // self include Chris@16: Chris@16: #include // for BOOST_STATIC_CONSTANT Chris@16: #include // for boost::uint_t Chris@16: Chris@16: #include // for UCHAR_MAX, etc. Chris@16: #include // for std::size_t Chris@16: Chris@16: #include // for std::numeric_limits Chris@16: Chris@16: // Chris@16: // We simply cannot include this header on gcc without getting copious warnings of the kind: Chris@16: // Chris@16: // boost/integer/integer_mask.hpp:93:35: warning: use of C99 long long integer constant Chris@16: // Chris@16: // And yet there is no other reasonable implementation, so we declare this a system header Chris@16: // to suppress these warnings. Chris@16: // Chris@16: #if defined(__GNUC__) && (__GNUC__ >= 4) Chris@16: #pragma GCC system_header Chris@16: #endif Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: Chris@16: Chris@16: // Specified single-bit mask class declaration -----------------------------// Chris@16: // (Lowest bit starts counting at 0.) Chris@16: Chris@16: template < std::size_t Bit > Chris@16: struct high_bit_mask_t Chris@16: { Chris@16: typedef typename uint_t<(Bit + 1)>::least least; Chris@16: typedef typename uint_t<(Bit + 1)>::fast fast; Chris@16: Chris@16: BOOST_STATIC_CONSTANT( least, high_bit = (least( 1u ) << Bit) ); Chris@16: BOOST_STATIC_CONSTANT( fast, high_bit_fast = (fast( 1u ) << Bit) ); Chris@16: Chris@16: BOOST_STATIC_CONSTANT( std::size_t, bit_position = Bit ); Chris@16: Chris@16: }; // boost::high_bit_mask_t Chris@16: Chris@16: Chris@16: // Specified bit-block mask class declaration ------------------------------// Chris@16: // Makes masks for the lowest N bits Chris@16: // (Specializations are needed when N fills up a type.) Chris@16: Chris@16: template < std::size_t Bits > Chris@16: struct low_bits_mask_t Chris@16: { Chris@16: typedef typename uint_t::least least; Chris@16: typedef typename uint_t::fast fast; Chris@16: Chris@16: BOOST_STATIC_CONSTANT( least, sig_bits = (~( ~(least( 0u )) << Bits )) ); Chris@16: BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) ); Chris@16: Chris@16: BOOST_STATIC_CONSTANT( std::size_t, bit_count = Bits ); Chris@16: Chris@16: }; // boost::low_bits_mask_t Chris@16: Chris@16: Chris@16: #define BOOST_LOW_BITS_MASK_SPECIALIZE( Type ) \ Chris@16: template < > struct low_bits_mask_t< std::numeric_limits::digits > { \ Chris@16: typedef std::numeric_limits limits_type; \ Chris@16: typedef uint_t::least least; \ Chris@16: typedef uint_t::fast fast; \ Chris@16: BOOST_STATIC_CONSTANT( least, sig_bits = (~( least(0u) )) ); \ Chris@16: BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) ); \ Chris@16: BOOST_STATIC_CONSTANT( std::size_t, bit_count = limits_type::digits ); \ Chris@16: } Chris@16: Chris@16: #ifdef BOOST_MSVC Chris@16: #pragma warning(push) Chris@16: #pragma warning(disable:4245) // 'initializing' : conversion from 'int' to 'const boost::low_bits_mask_t<8>::least', signed/unsigned mismatch Chris@16: #endif Chris@16: Chris@16: BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned char ); Chris@16: Chris@16: #if USHRT_MAX > UCHAR_MAX Chris@16: BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned short ); Chris@16: #endif Chris@16: Chris@16: #if UINT_MAX > USHRT_MAX Chris@16: BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned int ); Chris@16: #endif Chris@16: Chris@16: #if ULONG_MAX > UINT_MAX Chris@16: BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned long ); Chris@16: #endif Chris@16: Chris@16: #if defined(BOOST_HAS_LONG_LONG) Chris@16: #if ((defined(ULLONG_MAX) && (ULLONG_MAX > ULONG_MAX)) ||\ Chris@16: (defined(ULONG_LONG_MAX) && (ULONG_LONG_MAX > ULONG_MAX)) ||\ Chris@16: (defined(ULONGLONG_MAX) && (ULONGLONG_MAX > ULONG_MAX)) ||\ Chris@16: (defined(_ULLONG_MAX) && (_ULLONG_MAX > ULONG_MAX))) Chris@16: BOOST_LOW_BITS_MASK_SPECIALIZE( boost::ulong_long_type ); Chris@16: #endif Chris@16: #elif defined(BOOST_HAS_MS_INT64) Chris@16: #if 18446744073709551615ui64 > ULONG_MAX Chris@16: BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned __int64 ); Chris@16: #endif Chris@16: #endif Chris@16: Chris@16: #ifdef BOOST_MSVC Chris@16: #pragma warning(pop) Chris@16: #endif Chris@16: Chris@16: #undef BOOST_LOW_BITS_MASK_SPECIALIZE Chris@16: Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: Chris@16: #endif // BOOST_INTEGER_INTEGER_MASK_HPP