Namespaces
Variants

std::weak_ptr<T>:: owner_equal

From cppreference.net

Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
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_before ( other ) && ! other. owner_before ( * this ) true である場合に限り、 owner_equal ( other ) true となります。

この順序付けは、共有ポインタおよび弱ポインタを非順序連想コンテナのキーとして使用できるようにするために用いられます。通常は std::owner_equal を通じて実現されます。

目次

パラメータ

other - 比較対象の std::shared_ptr または std::weak_ptr

戻り値

true が返されるのは、 * this other が所有権を共有している場合、または両方が空の場合です。それ以外の場合は false が返されます。

注記

機能テスト マクロ 標準 機能
__cpp_lib_smart_ptr_owner_equality 202306L (C++26) std::weak_ptr 非順序連想コンテナ のキーとして使用可能にする

関連項目

共有ポインタと弱ポインタの混合型所有者ベース等値比較を提供する
(クラス)