5 #include <boost/range/irange.hpp>
9 // Macro that defines & and &= for an enum class. Add more when needed.
11 #define ENUM_ENABLE_BITWISE(enum_class) \
12 static enum_class operator&(enum_class lhs, enum_class rhs) \
14 return static_cast<enum_class>( \
15 static_cast<std::underlying_type<enum_class>::type>(lhs) \
16 & static_cast<std::underlying_type<enum_class>::type>(rhs)); \
18 static enum_class& operator&=(enum_class& lhs, enum_class rhs) \
26 // For enum classes starting at 0 and without any gaps with a terminating count constant.
28 const std::vector<E>& enum_constants()
30 typedef typename std::underlying_type<E>::type integer;
32 static const auto ints = boost::irange(static_cast<integer>(0), static_cast<integer>(E::count));
33 static const auto result = cpplinq::from(ints.begin(), ints.end())
35 .select([](int i) { return static_cast<E>(i); })