Or as alternative return a non-owning pointer.
References are non-null by definition.
-----Ursprüngliche Nachricht-----
Von: Henry Miller via Std-Proposals <std-proposals@lists.isocpp.org>
Betreff: Re: [std-proposals] null reference
you want the container to return a std::optional not a null reference. the nice thing about a reference is in practice nobody writes code to make them null even though it is easy and works as expected in most cases (i have done it to prove a point. No I won't share more, the conclusion is don't do that)
throwing an exception is sometimes a useful alternative, as is the std::expected variant of exceptions. Optional is likely what you want, and it is much less confusing.