std::owner_less
| ヘッダ <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_ptr と std::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 を参照してください)。
特殊化
|
標準ライブラリは
|
(C++17以上) |
メンバ型
|
(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以上) | |
オーナーベースのセマンティクスを用いて lhs と rhs を比較します。 実質的に lhs.owner_before(rhs) を呼びます。
順序は狭義弱順序関係です。
lhs と rhs はどちらも空であるか所有権を共有する場合にのみ同等です。
引数
| lhs, rhs | - | 比較する共有所有権のポインタ |
戻り値
オーナーベースの順序付けによって決定されるところによって lhs が rhs より小さい場合は true。
欠陥報告
以下の動作変更欠陥報告は以前に発行された C++ 標準に遡って適用されました。
| DR | 適用先 | 発行時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 2873 | C++11 | the operator()'s might not be declared noexcept | declared noexcept |
関連項目
| shared_ptr のオーナーベースの順序付けを提供します ( std::shared_ptr<T>のパブリックメンバ関数)
| |
| weak_ptr のオーナーベースの順序付けを提供します ( std::weak_ptr<T>のパブリックメンバ関数)
|