std::owner_equal
From cppreference.com
| ヘッダ <memory> で定義 |
||
| struct owner_equal; |
(C++26以降) | |
この関数オブジェクトは、std::weak_ptr と std::shared_ptr の両方に対して、値ベースではなく所有権ベースの混合型等価比較を提供します。この比較では、2つのスマートポインタは、両方が空であるか、または `get()` によって取得される生ポインタの値が異なる場合(例:同じオブジェクト内の異なるサブオブジェクトを指している場合)でも、所有権を共有している場合にのみ等価とみなされます。
これは、std::shared_ptr および std::weak_ptr をキーとして、std::owner_hash と共に順序なし連想コンテナを構築する際に推奨される比較述語です。つまり、std::unordered_map<std::shared_ptr<T>, U, std::owner_hash, std::owner_equal> または std::unordered_map<std::weak_ptr<T>, U, std::owner_hash, std::owner_equal> の場合です。
3)
std::owner_equal は、引数からパラメータ型を推論します。目次 |
[編集] ネストされた型
| ネストされた型 | 定義 |
is_transparent
|
unspecified |
[編集] メンバ関数
| operator() |
引数を所有者ベースのセマンティクスで比較する (関数) |
std::owner_equal::operator()
| template< class T, class U > bool operator()( const std::shared_ptr<T>& lhs, |
(C++26以降) | |
| template< class T, class U > bool operator()( const std::shared_ptr<T>& lhs, |
(C++26以降) | |
| template< class T, class U > bool operator()( const std::weak_ptr<T>& lhs, |
(C++26以降) | |
| template< class T, class U > bool operator()( const std::weak_ptr<T>& lhs, |
(C++26以降) | |
lhs と rhs を所有権ベースのセマンティクスで比較します。事実上、lhs.owner_equal(rhs) を呼び出します。
等価比較は同値関係です。
lhs と rhs は、両方が空であるか、または所有権を共有している場合にのみ等価です。
パラメータ
| lhs, rhs | - | 比較する共有所有権ポインタ |
戻り値
true 、lhs と rhs が両方とも空であるか、または所有権ベースの等価比較によって決定されるように所有権を共有している場合。false それ以外の場合。
[編集] 注記
| 機能テストマクロ | 値 | 規格 | 機能 |
|---|---|---|---|
__cpp_lib_smart_ptr_owner_equality |
202306L |
(C++26) | 順序なし連想コンテナのキーとして std::shared_ptr および std::weak_ptr を使用できるようにします。 |
[編集] 関連項目
| (C++26) |
共有ポインタの所有権ベースの等価比較を提供します。 ( std::shared_ptr<T> の public メンバ関数) |
| (C++26) |
weak ポインタの所有権ベースの等価比較を提供します。 ( std::weak_ptr<T> の public メンバ関数) |