Summary
This episode provides a comprehensive guide to C++ unions, explaining their core properties and evolution since C++98. Jason demonstrates how unions can be anonymous, that only one member can be active at a time, and how accessing inactive members is undefined behavior. The episode covers the challenges of managing non-trivial types in unions, including memory management and proper construction/destruction, and culminates with a minimal implementation of an Optional-like class to demonstrate proper union usage patterns.
Related C++ Standard Sections
This episode covers topics found in these sections of the C++ standard:
-
[class.access]45% match -
[ptr.launder]43% match