命名空间
变体
操作

operator==, <=>(std::reference_wrapper)

来自 cppreference.cn
< cpp‎ | 工具‎ | 函数‎ | 引用包装器
 
 
 
函数对象
函数调用
(C++17)(C++23)
恒等函数对象
(C++20)
透明运算符包装器
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

旧绑定器和适配器
(直到 C++17*)
(直到 C++17*)
(直到 C++17*)
(直到 C++17*)  
(直到 C++17*)
(直到 C++17*)(直到 C++17*)(直到 C++17*)(直到 C++17*)
(直到 C++20*)
(直到 C++20*)
(直到 C++17*)(直到 C++17*)
(直到 C++17*)(直到 C++17*)

(直到 C++17*)
(直到 C++17*)(直到 C++17*)(直到 C++17*)(直到 C++17*)
(直到 C++20*)
(直到 C++20*)
 
 
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,5) 使用 synth-three-way 比较两个 reference_wrapper 对象。
4) 仅当表达式 synth-three-way(lhs.get(), rhs.get()) 格式良好时,此重载才参与重载决议。
5) 仅当满足以下所有条件时,此重载才参与重载决议
6) 使用 synth-three-way 比较 reference_wrapper 对象和引用。
仅当表达式 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 的比较

[编辑] 示例