为什么 std::optional 对 std::nullopt 类型的操作数有一个特殊的相等运算符
Why does std::optional have a special equality operator for operand of the type std::nullopt
class模板std::optional
有转换构造函数
constexpr optional(nullopt_t) noexcept;
那么问题来了,为什么在C++标准中声明了特殊的单一相等运算符
template<class T> constexpr bool operator==(const optional<T>&, nullopt_t) noexcept;
当std::nullopt
仅用作第二个操作数时?
(例如,参见 C++ 20 Draft N 4860
// 20.6.7, comparison with nullopt
template<class T> constexpr bool operator==(const optional<T>&, nullopt_t) noexcept;
)
引入这个特殊运算符的原因是什么?
您正在查看 C++20 草案。草稿不迟于 N4820 had all the equality operators. They were later removed [likely] because of the introduction of rewritten candidates.
class模板std::optional
有转换构造函数
constexpr optional(nullopt_t) noexcept;
那么问题来了,为什么在C++标准中声明了特殊的单一相等运算符
template<class T> constexpr bool operator==(const optional<T>&, nullopt_t) noexcept;
当std::nullopt
仅用作第二个操作数时?
(例如,参见 C++ 20 Draft N 4860
// 20.6.7, comparison with nullopt
template<class T> constexpr bool operator==(const optional<T>&, nullopt_t) noexcept;
)
引入这个特殊运算符的原因是什么?
您正在查看 C++20 草案。草稿不迟于 N4820 had all the equality operators. They were later removed [likely] because of the introduction of rewritten candidates.