Back To Schedule

Fun with Flags

Type-safe bitwise operations

17:15 - 18:00 Wednesday 1st May 2024 MT Bethe Hall
Beginner
Intermediate
Advanced
Generic/Metaprogramming

Flag-like integer types offer a lot of nice properties:

  • easy to define, e.g. as macros, integer constants or enumerators
  • language support for setting and querying through bitwise operators
  • compact representation in memory
  • simple bulk transfer in interfaces (uint32_t can hold up to 32 options)
  • enforces the usage of names (preventing bool parameters in interfaces)

But on the other hand they are inherently type unsafe:

  • values from different flag-types can be combined
  • all types with built-in support for bitwise operators are implicitly convertibility to int
  • built-in bitwise operators return int
  • no distinction on the type level between flag-values and their bitwise negations

In this talk we present the library Boost.Flags which solves those problems in a non-intrusive and zero-overhead way.
Just a template-specialization away from type checking your flags!

View Slides

Tobias Loew

Software ArchitectIqony Solutions

Born in the analog year of 1973.

Made my first programming experience on a Commodore 64.

Wrote a course-management software while in high-school (1992), which is still in use.

Finished university with a Phd in Maths: math-models for functional languages.

Started C++ in 1999 working on a thermodynamic simulation tool.

Got a large Boost when I stumbled over its libraries.

Frequent BoostCon/C++Now attendant/speaker since then.