The Problem We're Actually Solving Let's start before the code. Imagine you write a function that divides two numbers. Easy, right? Except... what happens if someone tries to divide by zero? Your function needs a way to say "hey, something went wrong here" without crashing the whole program or lying about the result. For decades, C++ programmers have had a few messy options: Throw an exception — works, but exceptions are expensive, and some codebases (game engines, embedded systems) avoid them entirely. Return an error code — cheap, but easy to ignore. Nobody checks return codes reliably, and you lose the "why" behind the failure. Use an output parameter — pass a pointer or reference to fill in with an error. Clunky and easy to mess up. Return a std::optional — tells you something failed, but not what or why . C++23 gives us a much cleaner tool: std::expected . Think of it as a box that either contains your successful result, or contains the ...