From Jason Turner
Watch on YouTube

Summary

This episode explores std::optional, a C++17 feature that provides a way to represent optional values without dynamic memory allocation. Jason demonstrates key aspects of std::optional, including its memory layout (sized to hold the value plus metadata), value access methods (value() and value_or()), and assignment behavior. He highlights how std::optional handles object lifetimes for contained values and shows how to use emplace() to construct objects in-place when working with move/copy-restricted types, while noting that std::optional isn't constexpr-compatible in C++17.

Resources

Tags