Fun with Flags - C++ Type-safe Bitwise Operations
summary
Library Boost.Flags implements type-safe bitwise operators for enum-based flags by adding a complementary flag type and ADL-visible operator overloads enabled via a macro. It keeps operations non-intrusive and zero-overhead in optimized builds, prevents mixing different flag types (and rules out common UB by using underlying integer for complements), supports scoped and unscoped enums, includes helpers like subset/disjoint, and already sees ~120 uses in a 25-year codebase (Absolum) with a broad compiler/test matrix.
AI-written summary · about
chapters (6)
- 0:00Introduction to bitwise flags
- 3:35Problems with current methods
- 11:53The mathematics of bit sets
- 25:23Library demonstration
- 29:53Library design and comparison
- 49:05Q&A and concluding remarks
related talks
01h 08mFrom Numerical Cosmology to Efficient Bit Abstractions for the Standard Library
06mLightning Talk: Safe Arithmetic Speed-Run: Experimental C++ Library
12mExtreme Type Safety with Opaque Typedefs
53mC++ Features You Might Not Know
55mUsing Integers as Arrays of Bitfields a.k.a. SWAR Techniques
51mTypical C++, but Why?
54mTypical C++, But Why?
05mFighting Compiler warnings
