I am sure there is a good reason for that, but why is the "optional reference" not simply a pointer? Is that not semantically the same thing, but way easier to deal with.
If you return me a pointer, what does that communicate to me? Who owns it? Is nullptr an error or something I should expect? Is this documented somewhere? The advantage of std::optional is explicit about intent. I just have to look at the API and I know immediately what the author intended with the return value.
All good points, and this one in particular. Never though about it, but sure, a returned pointer might imply returned ownership, whereas an (optional) reference never means that. Thanks!
14
u/bartgrumbel 6d ago
I am sure there is a good reason for that, but why is the "optional reference" not simply a pointer? Is that not semantically the same thing, but way easier to deal with.
I.e. why
and not simply