Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That's putting the cart before the horse. Languages are designed for developers to use, not compilers to optimize. The intention and use of std::optional is clear.

Edit: My point, if not clear, is that the compiler should add the extra bit of code for when an optional is empty automatically, rather than requiring that an optional be defined (it's optional!) unless it is explicitly typed as monostate.



That makes even less sense, what "extra bit of code" are you talking about? monostate is not designed to be used with optional: although there's the odd case where that's useful an optional<monostate> is bijective to a boolean, and because C++ does not have zero-sized types it's less efficient (as it takes two bytes).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: