'std::expected and reference return type

I am trying to use the proposed std::expected or some variation of the technique to replace my exception-using code, but I can't figure out how to use it in functions that return references in the current implementation. Any help would be appreciated.

P.S. Please don't tell me I should be using exceptions. I can't in this case, and the why of it is irrelevant to this question.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source