名稱空間
變體
操作

std::shared_ptr<T>::owner_equal

來自 cppreference.com
 
 
記憶體管理庫
(僅作說明*)
未初始化記憶體演算法
(C++17)
(C++17)
(C++17)
受約束的未初始化
記憶體演算法
C 庫

分配器
記憶體資源
垃圾回收支援
(C++11)(直到 C++23)
(C++11)(直到 C++23)
(C++11)(直到 C++23)
(C++11)(直到 C++23)
(C++11)(直到 C++23)
(C++11)(直到 C++23)
未初始化儲存
(直到 C++20*)
(直到 C++20*)
顯式生命週期管理
 
 
template< class Y >
bool owner_equal( const std::shared_ptr<Y>& other ) const noexcept;
(1) (C++26 起)
template< class Y >
bool owner_equal( const std::weak_ptr<Y>& other ) const noexcept;
(2) (C++26 起)

檢查此 shared_ptrother 是否共享所有權,或者是否都為空。比較結果是,兩個智慧指標僅在它們都為空或它們都擁有同一物件時才比較相等,即使透過 get() 獲取的指標值不同(例如,因為它們指向同一物件內不同的子物件)。

成員函式 owner_equal 是一種等價關係,使得 !owner_before(other) && !other.owner_before(*this)true 當且僅當 owner_equal(other)true

此排序用於使共享指標和弱指標可用作無序關聯容器中的鍵,通常透過 std::owner_equal

目錄

[編輯] 引數

其他 - 要比較的 std::shared_ptrstd::weak_ptr

[編輯] 返回值

如果 *thisother 共享所有權或都為空,則返回 true。否則,返回 false

[編輯] 注意

特性測試 標準 特性
__cpp_lib_smart_ptr_owner_equality 202306L (C++26) 允許在無序關聯容器中使用 std::shared_ptr 作為鍵

[編輯] 示例

[編輯] 另請參見

提供基於所有者的共享指標和弱指標的混合型別相等比較
(類) [編輯]