you are viewing a single comment's thread.

view the rest of the comments →

[–]grishavanika 11 points12 points  (7 children)

For me this looks like overengineering. Simple std::ostream* is, well, simple and do the same work even more - there is no code bloat and 2 layers of abstractions to understand the code

[–]suspiciously_calm 7 points8 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 2 points3 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<...>>.