名前空間
変種
操作

std::owner_equal

From cppreference.com
< cpp‎ | memory
 
 
メモリ管理ライブラリ
(説明用*)
未初期化メモリのアルゴリズム
(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まで*)
明示的な生存期間管理
 
ヘッダ <memory> で定義
struct owner_equal;
(C++26以降)

この関数オブジェクトは、std::weak_ptrstd::shared_ptr の両方に対して、値ベースではなく所有権ベースの混合型等価比較を提供します。この比較では、2つのスマートポインタは、両方が空であるか、または `get()` によって取得される生ポインタの値が異なる場合(例:同じオブジェクト内の異なるサブオブジェクトを指している場合)でも、所有権を共有している場合にのみ等価とみなされます。

1) std::shared_ptr および std::weak_ptr 以外の型に対しては、所有権ベースの混合型等価比較は提供されません。
2) std::shared_ptrstd::weak_ptr の所有権ベースの混合型等価比較。
これは、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,

                 const std::shared_ptr<U>& rhs ) const noexcept;
(C++26以降)
template< class T, class U >

bool operator()( const std::shared_ptr<T>& lhs,

                 const std::weak_ptr<U>& rhs ) const noexcept;
(C++26以降)
template< class T, class U >

bool operator()( const std::weak_ptr<T>& lhs,

                 const std::shared_ptr<U>& rhs ) const noexcept;
(C++26以降)
template< class T, class U >

bool operator()( const std::weak_ptr<T>& lhs,

                 const std::weak_ptr<U>& rhs ) const noexcept;
(C++26以降)

lhsrhs を所有権ベースのセマンティクスで比較します。事実上、lhs.owner_equal(rhs) を呼び出します。

等価比較は同値関係です。

lhsrhs は、両方が空であるか、または所有権を共有している場合にのみ等価です。

パラメータ

lhs, rhs - 比較する共有所有権ポインタ

戻り値

truelhsrhs が両方とも空であるか、または所有権ベースの等価比較によって決定されるように所有権を共有している場合。false それ以外の場合。

[編集] 注記

機能テストマクロ 規格 機能
__cpp_lib_smart_ptr_owner_equality 202306L (C++26) 順序なし連想コンテナのキーとして std::shared_ptr および std::weak_ptr を使用できるようにします。

[編集] 関連項目

共有ポインタの所有権ベースの等価比較を提供します。
(std::shared_ptr<T> の public メンバ関数) [編集]
weak ポインタの所有権ベースの等価比較を提供します。
(std::weak_ptr<T> の public メンバ関数) [編集]
English 日本語 中文(简体) 中文(繁體)