Fun with Flags - C++ Type-safe Bitwise Operations - Tobias Loew - C++Now 2024

preview_player
Показать описание
---

Fun with Flags - C++ Type-safe Bitwise Operations - Tobias Loew - C++Now 2024
---

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!
---

---

Tobias Loew

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.
---

C++Now 2025 - 28th April - 2nd May
C++Now is an annual onsite international C++ programming and coding conference held in Aspen, Colarado. For all C++ developers, C++ software engineers and those involved with the C++ language, CppNow provides an indepth and technical content provided by the best and brightest C++ experts of the C++ world.
Video Sponsors: millennium and think-cell
---

---

#boost #cpp #cppprogramming #cplusplus #cplusplusprogramming
Комментарии
Автор

22:29 - yikes - didn't know about that UB.

zxxvcc