1 // boost/detail/bitmask.hpp ------------------------------------------------//
3 // Copyright Beman Dawes 2006
5 // Distributed under the Boost Software License, Version 1.0
6 // http://www.boost.org/LICENSE_1_0.txt
8 // Usage: enum foo { a=1, b=2, c=4 };
9 // BOOST_BITMASK( foo );
15 #ifndef BOOST_BITMASK_HPP
16 #define BOOST_BITMASK_HPP
18 #include <boost/cstdint.hpp>
20 #define BOOST_BITMASK(Bitmask) \
22 inline Bitmask operator| (Bitmask x , Bitmask y ) \
23 { return static_cast<Bitmask>( static_cast<boost::int_least32_t>(x) \
24 | static_cast<boost::int_least32_t>(y)); } \
26 inline Bitmask operator& (Bitmask x , Bitmask y ) \
27 { return static_cast<Bitmask>( static_cast<boost::int_least32_t>(x) \
28 & static_cast<boost::int_least32_t>(y)); } \
30 inline Bitmask operator^ (Bitmask x , Bitmask y ) \
31 { return static_cast<Bitmask>( static_cast<boost::int_least32_t>(x) \
32 ^ static_cast<boost::int_least32_t>(y)); } \
34 inline Bitmask operator~ (Bitmask x ) \
35 { return static_cast<Bitmask>(~static_cast<boost::int_least32_t>(x)); } \
37 inline Bitmask & operator&=(Bitmask & x , Bitmask y) \
38 { x = x & y ; return x ; } \
40 inline Bitmask & operator|=(Bitmask & x , Bitmask y) \
41 { x = x | y ; return x ; } \
43 inline Bitmask & operator^=(Bitmask & x , Bitmask y) \
44 { x = x ^ y ; return x ; }
46 #endif // BOOST_BITMASK_HPP