-6
我没有安装最新的编译器,以获得最终的std::optional
语义将要发生的提示。但在C++ 14中,有以下几种:C++是否在std :: min和std :: max下标准化std :: optional的行为?
#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);
}
不能编译。现在,在未来,我希望/希望在这种情况下z
会得到3
;如果oy = oint{}
则z
可能得到2
。
就像我期望在C++ 17中标准化或稍后提出标准化?或者,是未定义标准化(就像它在C++ 14中的排序)?
注意:这里的动机可能是我自己实现的事情,对于C++ 17之前的代码;如果有相关的计划是标准化的,我会尝试匹配。
我不明白这是如何混淆。 ['std :: max'](http://en.cppreference.com/w/cpp/algorithm/max)期望它的两个参数具有相同的类型。 – Justin
['std :: optional'](http://en.cppreference.com/w/cpp/utility/optional/operator_cmp)有比较运算符;你可以使用'std :: max(oint {x},oy)' – Justin
...或者作为一个更糟的选择,用'std :: max(x,oy.value_or(std :: numeric_limits :: min()));'。 –
dfri