C++26: std::optional -- Sandor Dargo
If you’re a regular reader of Sandor's blog, you know he's been sharing what he learned about new C++ language and library features ever since C++20. You probably also read his CppCon 2025 Trip Report. And this post is where the two come together.
C++26: std::optional<T&>
by Sandor Dargo
From the article:
At CppCon I attended a great talk by Steve Downey about
std::optional<T&>. Steve is the father of optional references—he co-authored P2988R12 with Peter Sommerlad.Let’s start with a little history. By now — at the end of 2025 — even C++17 feels like history. That’s when
std::optional<T>was introduced, giving us a way to represent “maybe a value” with value semantics, instead of relying on pointers. Butstd::optionalin C++17 (and later) couldn’t hold references — unless you wrapped them instd::reference_wrapper.C++26 finally fixes this gap.
What is
std::optional<T&>?
std::optional<T&>has three key characteristics:
- Unlike
std::optional<T>, it is not an owning type. It simply refers to an existing object.- It provides both reference and value-like semantics.
- Internally, it behaves like a pointer to
T, which may also benullptr.This last point is interesting: while
optional<T>can be seen asvariant<T, monostate>,optional<T&>is closer tovariant<T&, nullptr_t>. In practice, it’s a safer alternative to a non-owning raw pointer.

In this post, we’ll take a closer look at how to extend the earlier callback wrapper mechanism to handle regular function pointers as well as member functions. Along the way, we’ll examine some of the subtleties of inferring function pointer types from callable objects—especially when lambdas with auto parameters enter the picture.
This post chronicles a month-long experiment using C++26 reflections to automate the generation of pybind11 bindings, blending the promise of modern metaprogramming with real-world complexity. It offers a candid look at what worked beautifully, what fell short, and what future language features could make reflection-driven automation even more powerful.



The new Constexpr Debugger available in the first CLion 2025.3 EAP build allows you to stay in the compiler’s world and see what really happens – by stepping through evaluation, inspecting values, and confirming which if constexpr branch fired. Using it helps you understand exactly what the compiler is doing and fix issues faster.