std::weak_ptr<T>::owner_equal
來自 cppreference.com
template< class Y > bool owner_equal( const std::weak_ptr<Y>& other ) const noexcept; |
(1) | (C++26 起) |
template< class Y > bool owner_equal( const std::shared_ptr<Y>& other ) const noexcept; |
(2) | (C++26 起) |
檢查此 weak_ptr
與 other 是否共享所有權,或是否都為空。該比較使得兩個智慧指標僅在它們都為空,或它們都擁有同一物件時才比較為等價,即使透過 get() 獲得指標值不同(例如因為它們指向同一物件中的不同子物件)。
成員函式 owner_equal
是一種等價關係,使得當且僅當 owner_equal(other) 為 true 時,!owner_before(other) && !other.owner_before(*this) 為 true。
此順序用於使共享指標和弱指標可用作無序關聯容器中的鍵,通常透過 std::owner_equal 實現。
目錄 |
[編輯] 引數
其他 | - | 要比較的 std::shared_ptr 或 std::weak_ptr |
[編輯] 返回值
若 *this 和 other 共享所有權或均為空,則為 true。否則返回 false。
[編輯] 注意
特性測試宏 | 值 | 標準 | 特性 |
---|---|---|---|
__cpp_lib_smart_ptr_owner_equality |
202306L |
(C++26) | 允許將 std::weak_ptr 用作無序關聯容器中的鍵 |
[編輯] 示例
本節不完整 原因:示例 |
[編輯] 參閱
(C++26) |
提供基於所有者的共享指標和弱指標的混合型別相等比較 (類) |