Overview
Coursera Flash Sale
40% Off Coursera Plus for 3 Months!
Grab it
Explore the comprehensive evolution of std::optional in C++ through this conference talk that traces its journey from the original 2005 proposal to the upcoming C++26 implementation. Discover how Optional was first introduced in C++17 with constraints preventing reference types, and learn about the upcoming addition of optional lvalue references in C++26. Examine the key design decisions and trade-offs that shaped this fundamental C++ feature over nearly two decades of development.
Delve into the historical progression starting with Boost.Optional and the early "N1878: A Proposal to Add an Utility Class to Represent Optional Objects" proposal, understanding the initial concerns surrounding reference specialization. Follow the evolution through subsequent proposals including P1175R0 for C++20 (which was not adopted), P1683R0's survey of existing optional reference behavior in 2020, and the successful P2988R0 proposal that achieved Library Working Group approval in 2023.
Learn about the recent P3168R0 proposal from 2024 that adds range support to optional, transforming it from a simple wrapper to a range of zero or one elements. Understand how the reference implementation and test cases for views::maybe contributed to validating the additional interfaces, and discover how this work became one of the first Beman libraries, benefiting from increased visibility and community feedback.
Examine the core technical challenges that made this evolution so complex, particularly how references don't behave as values and how types containing references lack value semantics. Understand why references don't fit comfortably within the C++ type system and how pointers, while providing reference semantics, suffer from under-constrained and unsafe behavior. Explore how these discussions served as a proxy for broader questions about reference semantic types within value semantic types in the standard library, affecting other "sum" types like expected and variant, as well as view types such as single.
Gain insights into related topics including Project Beman, the distinction between value and reference semantic types, sum and product types, CoData concepts, and lifetime safety considerations that influenced these design decisions throughout the optional's evolution.
Syllabus
Steve Downey has been a programmer for more than 30 years. Steve graduated from SUNY Purchase with a BS in Mathematics. A Computer Science degree would have involved two classes before 11:00 am, so was impossible.
Taught by
CppCon