Hacker News new | ask | show | jobs
by yongjik 3378 days ago
std::optional is nice if you have a class with invariants that you want to always maintain (i.e., you don't want to deal with the pesky "uninitialized" state). You can build a class that always requires proper parameter in its constructor, and then you apply optional<> only when you defer initialization.

In most cases, I imagine the performance penalty would be dwarfed by the cost of actually using the class.