◐ Shell
clean mode source ↗

std::owner_less - cppreference.com

提供: cppreference.com

<tbody> </tbody> <tbody class="t-dcl-rev t-dcl-rev-num "> </tbody><tbody> </tbody>

ヘッダ <memory> で定義

(1)

template< class T > struct owner_less; /* undefined */

(C++11以上)
(C++17未満)

template< class T = void > struct owner_less; /* undefined */

(C++17以上)

template< class T > struct owner_less<std::shared_ptr<T>>;

(2) (C++11以上)

template< class T > struct owner_less<std::weak_ptr<T>>;

(3) (C++11以上)

template<> struct owner_less<void>;

(4) (C++17以上)

この関数オブジェクトは std::weak_ptrstd::shared_ptr 両方の型混合のオーナーベース (値ベースではなく) の順序付けを提供します。 順序は2つのスマートポインタがどちらも空の場合または所有権を共有している (例えば同じオブジェクト内の異なる部分オブジェクトを指しているなどにより、 get() によって取得される生のポインタ値が異なっていても) 場合にのみ同等であるようになります。

このクラステンプレートは

std::map<std::shared_ptr<T>, U, std::owner_less<std::shared_ptr<T>>>

std::map<std::weak_ptr<T>, U, std::owner_less<std::weak_ptr<T>>>

のように std::shared_ptr または std::weak_ptr をキーとして使用する連想コンテナを作るときに推奨される比較述語です。

デフォルトの operator< はウィークポインタに対しては定義されていませんし、同じオブジェクトに対する2つのシェアードポインタを間違って同等でないとみなす場合があります (shared_ptr::owner_before を参照してください)。

特殊化

標準ライブラリは T が指定されないときの std::owner_less の特殊化を提供します。 この場合、引数の型は実引数から推定されます (その場合でも各引数は std::shared_ptr または std::weak_ptr のいずれかでなければなりません)。

(C++17以上)

メンバ型

メンバ型 定義
result_type(C++17で非推奨) 2-3) bool
first_argument_type(C++17で非推奨) 2) std::shared_ptr<T>
3) std::weak_ptr<T>
second_argument_type(C++17で非推奨) 2) std::shared_ptr<T>
3) std::weak_ptr<T>
(C++20未満)

メンバ関数

std::owner_less::operator()

<tbody> </tbody>

owner_less<shared_ptr<T>> テンプレート特殊化のみのメンバ

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

(C++11以上)

owner_less<weak_ptr<T>> テンプレート特殊化のみのメンバ

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

(C++11以上)

両方のテンプレート特殊化のメンバ

bool operator()( const std::shared_ptr<T>& lhs, const std::weak_ptr<T>& rhs ) const noexcept;

(C++11以上)

bool operator()( const std::weak_ptr<T>& lhs, const std::shared_ptr<T>& rhs ) const noexcept;

(C++11以上)

オーナーベースのセマンティクスを用いて lhsrhs を比較します。 実質的に lhs.owner_before(rhs) を呼びます。

順序は狭義弱順序関係です。

lhsrhs はどちらも空であるか所有権を共有する場合にのみ同等です。

引数

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

戻り値

オーナーベースの順序付けによって決定されるところによって lhsrhs より小さい場合は true

欠陥報告

以下の動作変更欠陥報告は以前に発行された C++ 標準に遡って適用されました。

DR 適用先 発行時の動作 正しい動作
LWG 2873 C++11 the operator()'s might not be declared noexcept declared noexcept

関連項目