-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