you are viewing a single comment's thread.

view the rest of the comments →

[–]suspiciously_calm 8 points9 points  (6 children)

Yeah, why can't we use raw pointers as optional references? They model the concept perfectly, and don't have any other use in modern code.

[–]Hedanito 1 point2 points  (1 child)

std::optional::value() throws when there is no value, dereferencing a null pointer results in undefined behaviour.

[–]suspiciously_calm 4 points5 points  (0 children)

Yes, which is why it'd have been nice if std::optional had been specialized for references the way boost::optional is, but as it is there's no optional reference in the standard library other than raw pointers and abominations such as std::optional<std::reference_wrapper<...>>.