Ben Saks

Compile-Time Programming in C++ Using Constexpr
Status: Available NowPrerequisite: Solid knowledge of the C, as well as the fundamentals of C++ classes, constructors, and the const qualifier.
C++’s constexpr qualifier is a powerful tool for writing “constant expressions” — that is, expressions that can be computed at compile time. These constant expressions have several advantages over non-constant expressions, particularly for embedded systems. Objects with values that are constant expressions can be placed in ROM (read-only memory), and can be used as array dimensions, case labels, and enumerator initializers. Moreover, code that uses constant expressions is generally smaller and faster than similar code that uses non-constant expressions.
In this session, we’ll look at how you can use the constexpr qualifier to write functions that yield constant expressions. We’ll examine the differences between const and constexpr objects and see why const objects don’t necessarily qualify as constant expressions. We’ll also discuss the related C++20 keywords consteval and constinit and see how they fit into the picture.
This session covers:
- A review of the fundamentals of const
- constexpr functions
- constexpr objects
- consteval functions
- constinit objects
Live Q&A - Compile-Time Programming in C++ Using Constexpr
Status: Available NowLive Q&A with Ben Saks for the talk titled Compile-Time Programming in C++ Using Constexpr