Namespaces
Variants

std:: 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)
定義先ヘッダ <memory>
struct owner_equal ;
(C++26以降)

この関数オブジェクトは、所有者ベース(値ベースではなく)の混合型等値比較を std::weak_ptr および std::shared_ptr に対して提供します。この比較は、2つのスマートポインタがともに空である場合、または所有権を共有している場合にのみ等価と判定されます。たとえ get() によって取得された生ポインタの値が異なっていても(例えば同じオブジェクト内の異なるサブオブジェクトを指している場合など)、この条件は変わりません。

1) Owner-based mixed-type equal comparisonは、 std::shared_ptr および std::weak_ptr 以外の型に対しては提供されていません。
2) std::shared_ptr std::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以降)

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

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

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

パラメータ

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

戻り値

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

注記

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

関連項目

shared pointerのオーナーベースの等値比較を提供する
( std::shared_ptr<T> のpublicメンバ関数)
weak pointerのオーナーベースの等値比較を提供する
( std::weak_ptr<T> のpublicメンバ関数)