integer_mask.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef BOOST_INTEGER_INTEGER_MASK_HPP
00011 #define BOOST_INTEGER_INTEGER_MASK_HPP
00012
00013 #include <boost/integer_fwd.hpp>
00014
00015 #include <boost/config.hpp>
00016 #include <boost/integer.hpp>
00017
00018 #include <climits>
00019 #include <cstddef>
00020
00021 #include <boost/limits.hpp>
00022
00023
00024 namespace boost
00025 {
00026
00027
00028
00029
00030
00031 template < std::size_t Bit >
00032 struct high_bit_mask_t
00033 {
00034 typedef typename uint_t<(Bit + 1)>::least least;
00035 typedef typename uint_t<(Bit + 1)>::fast fast;
00036
00037 BOOST_STATIC_CONSTANT( least, high_bit = (least( 1u ) << Bit) );
00038 BOOST_STATIC_CONSTANT( fast, high_bit_fast = (fast( 1u ) << Bit) );
00039
00040 BOOST_STATIC_CONSTANT( std::size_t, bit_position = Bit );
00041
00042 };
00043
00044
00045
00046
00047
00048
00049 template < std::size_t Bits >
00050 struct low_bits_mask_t
00051 {
00052 typedef typename uint_t<Bits>::least least;
00053 typedef typename uint_t<Bits>::fast fast;
00054
00055 BOOST_STATIC_CONSTANT( least, sig_bits = (~( ~(least( 0u )) << Bits )) );
00056 BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) );
00057
00058 BOOST_STATIC_CONSTANT( std::size_t, bit_count = Bits );
00059
00060 };
00061
00062
00063 #define BOOST_LOW_BITS_MASK_SPECIALIZE( Type ) \
00064 template < > struct low_bits_mask_t< std::numeric_limits<Type>::digits > { \
00065 typedef std::numeric_limits<Type> limits_type; \
00066 typedef uint_t<limits_type::digits>::least least; \
00067 typedef uint_t<limits_type::digits>::fast fast; \
00068 BOOST_STATIC_CONSTANT( least, sig_bits = least(~( least(0u) )) ); \
00069 BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) ); \
00070 BOOST_STATIC_CONSTANT( std::size_t, bit_count = limits_type::digits ); \
00071 }
00072
00073 BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned char );
00074
00075 #if USHRT_MAX > UCHAR_MAX
00076 BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned short );
00077 #endif
00078
00079 #if UINT_MAX > USHRT_MAX
00080 BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned int );
00081 #endif
00082
00083 #if ULONG_MAX > UINT_MAX
00084 BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned long );
00085 #endif
00086
00087 #undef BOOST_LOW_BITS_MASK_SPECIALIZE
00088
00089
00090 }
00091
00092
00093 #endif // BOOST_INTEGER_INTEGER_MASK_HPP