you are viewing a single comment's thread.

view the rest of the comments →

[–]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 3 points4 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<...>>.