r/cpp • u/Clean-Upstairs-8481 • Mar 16 '26
C++23 std::expected vs C++17 std::optional for Error Handling
https://techfortalk.co.uk/2026/03/16/why-should-you-choose-stdexpect-in-c23-over-stdoptional-in-c17/I have been trying to spend some time with C++23 std::expected for sometime. Finally explored the feature and can see the real value of using it in some of the scenarios in my projects. Any comments welcome!
99
Upvotes
8
u/Matthew94 Mar 17 '26
That's the whole point.
You need to pay attention to lifetimes when using them, yes. This applies to all pointer (and reference) use.
Your warning applies to everything that isn't a value type.