名稱空間
變體
操作

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

來自 cppreference.com
< 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 的比較

[編輯] 示例