I don't have a very recent compiler installed to get a hint of what the final std::optional
semantics are going to be. But in C++14, the following:
#include <experimental/optional>
#include <algorithm>
int main()
{
using oint = std::experimental::optional<int>;
int x = std::max(1, 2);
auto oy = oint{3};
auto z = std::max(x, oy);
}
does not compile. Now, in the future, I would expect/hope that z
would get 3
in this case; and if oy = oint{}
then z
could get 2
.
Is something like what I expected standardized in C++17, or proposed for standardization later? Alternatively, is the undefinability standardized (like it sort of is in C++14)?
Note: The motivation here is possibly implementing something myself, for pre-C++17 code; if something relevant is planned to be standardized I'll try to match that.