operator==, <=>(std::reference_wrapper)
来自cppreference.com
< cpp | utility | functional | reference wrapper
friend constexpr bool operator==( reference_wrapper lhs, reference_wrapper rhs ); |
(1) | (C++26 起) |
friend constexpr bool operator==( reference_wrapper lhs, reference_wrapper<const T> rhs ); |
(2) | (C++26 起) |
friend constexpr bool operator==( reference_wrapper lhs, const T& ref ); |
(3) | (C++26 起) |
friend constexpr auto operator<=>( reference_wrapper lhs, reference_wrapper rhs ); |
(4) | (C++26 起) |
friend constexpr auto operator<=>( reference_wrapper lhs, reference_wrapper<const T> rhs ); |
(5) | (C++26 起) |
friend constexpr auto operator<=>( reference_wrapper lhs, const T& ref ); |
(6) | (C++26 起) |
实施 reference_wrapper
对象上的比较运算。
1,2) 比较两个
reference_wrapper
对象。当且仅当 lhs.get() 和 rhs.get() 相等时两对象比较相等。1) 此重载只有在表达式 lhs.get() == rhs.get() 良构且它的结果可转换到 bool 时才会参与重载决议。
2) 此重载只有在满足以下所有条件时才会参与重载决议:
- std::is_const_v<T> 是 false。
- 表达式 lhs.get() == rhs.get() 良构且它的结果可转换到 bool。
3) 比较
reference_wrapper
对象和一个引用。当且仅当 lhs.get() 等于 ref 时两形参比较相等。 此重载只有在表达式 lhs.get() == ref 良构且它的结果可转换到 bool 时才会参与重载决议。
4) 此重载只有在表达式 synth-three-way(lhs.get(), rhs.get()) 良构时才会参与重载决议。
5) 此重载只有在满足以下所有条件时才会参与重载决议:
- std::is_const_v<T> 是 false。
- 表达式 synth-three-way(lhs.get(), rhs.get()) 良构。
此重载只有在表达式 synth-three-way(lhs.get(), ref) 良构时才会参与重载决议。
<
、<=
、>
、>=
及 !=
运算符分别从 operator<=> 与 operator== 合成。
目录 |
[编辑] 参数
lhs, rhs | - | 要比较的 reference_wrapper 对象
|
ref | - | 要与 reference_wrapper 对象比较的引用
|
[编辑] 返回值
1,2) lhs.get() == rhs.get()。
3) lhs.get() == ref。
4,5) synth-three-way(lhs.get(), rhs.get())。
6) synth-three-way(lhs.get(), ref)。
[编辑] 异常
抛出比较所抛出的异常。
[编辑] 注解
operator<=> 的返回类型是从 return
语句推导的,以避免实例化 std::reference_wrapper<T> 时因为 synth-three-way-result<T> 非良构而产生硬错误。
功能特性测试宏 | 值 | 标准 | 功能特性 |
---|---|---|---|
__cpp_lib_reference_wrapper |
202403L |
(C++26) | std::reference_wrapper 的比较
|
[编辑] 示例
本节未完成 原因:暂无示例 |