P4280R0 — Expected over References
Steve Downey
LEWG
A function that can fail and otherwise returns a reference has no good return type today. `expected<T*,` `E>` lets a null pointer through as a success, and `expected<reference_wrapper<T>,` `E>` exposes the wrapper at every use. An error that is owned elsewhere, by a diagnostics engine or an error registry, has the same problem in the error position. We propose that `std::expected` hold an lvalue reference in the value position, the error position, or both.