I was reviewing the interface for the C++-17 std::optional class template and noticed that the reset and assignment from nullopt are not marked as constexpr.
The example:Actually this program prints some int (uninitialized value of type int). Also, libcxx uses assert-check for accessing non-engaged value.
While reading through GCC's implementation of std::optional I noticed something interesting. I know boost::optional is implemented as follows:
Is it possible to evaluate std::optional::value_or(expr) argument in a lazy way, so the expr were calculated only in the case of having no value? If not, what would be a proper replacement?