On Mon, Mar 16, 2026 at 12:00 PM Tobias Loew via Boost <boost@lists.boost.org> wrote:
I would like to gauge interest in a library [...] which provides type-safe, non-intrusive bitwise operators for C++ enumerations. [...] I am interested in hearing if the community sees a place for this in Boost
FWIW, I rolled-up my own a while back, like many I'm sure, so there's obviously a need, IMHO. I'd welcome a Boost quality one, which would be, I'm sure, heads and shoulders better than mine. --DD // Adapted (and fixed) from // https://softwareengineering.stackexchange.com/a/338472/189774 template <typename Enum> class BitFlags { static_assert(std::is_enum_v<Enum>); using underlying_t = typename std::underlying_type<Enum>::type; constexpr const static int number_of_bits = std::numeric_limits<underlying_t>::digits; public: ... private: std::bitset<number_of_bits> bits_; }; template <typename Enum> constexpr std::enable_if_t<std::is_enum_v<Enum>, BitFlags<Enum>> operator|(Enum left, Enum right) { return BitFlags<Enum>(left) | right; } template <typename Enum> constexpr std::enable_if_t<std::is_enum_v<Enum>, BitFlags<Enum>> operator&(Enum left, Enum right) { return BitFlags<Enum>(left) & right; } template <typename Enum> constexpr std::enable_if_t<std::is_enum_v<Enum>, BitFlags<Enum>> operator^(Enum left, Enum right) { return BitFlags<Enum>(left) ^ right; }