We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Taking a Byte Out of C++ - Avoiding Punning by Starting Lifetimes - Robert Leahy - CppCon 2022
Explore the power of C++'s type system to start lifetimes explicitly, avoiding undefined behavior and writing safer, more expressive code with concepts, functions, and wrappers.
- The C++ type system is powerful, but starts of lifetime are not explicitly declared.
- Concepts can be used to define and enforce well-defined behavior.
- Lifetime of an array of bytes starts the lifetime of an array of bytes.
- C++ programmers often implicitly start lifetimes without realizing it.
-
The
start_lifetime
concept can be used to provide explicit lifetime management. - The type system can be used as a lens to look at buffers of bytes.
-
The
updateAs
function can be used to start the lifetime of an array of bytes. - The type system can be used to ensure correctness and avoid undefined behavior.
- The C++ standard provides two ways to end the storage duration of an object.
- Constructors can bring objects into existence with invariance established.
- Lifetimes have implicitly begun in storage before the constructor has completed execution.
-
The
as_ implicit
concept can be used to define a sequence of values. -
The
start_lifetime
concept can be used to start the lifetime of a trivially constructible type. -
The
validate
function can be used to ensure that an object is in a valid state. - The type system can be used to write safer code and avoid undefined behavior.
-
The
start_lifetime
concept can be used to provide a way to start the lifetime of an object. -
The
_expected
wrapper can be used to provide a way to handle errors. - The type system can be used to write more expressive code.
-
The
start_lifetime
concept can be used to provide a way to start the lifetime of an object in a way that is safe and efficient. -
The
validate
function can be used to ensure that an object is in a valid state before using it.