- memory[meta header]
- std[meta namespace]
- weak_ptr[meta class]
- function template[meta id-type]
- cpp11[meta cpp]
template <class U>
bool
owner_before(const shared_ptr<U>& b) const; // (1) C++11
template <class U>
bool
owner_before(const shared_ptr<U>& b) const noexcept; // (1) C++17
template <class U>
constexpr bool
owner_before(const shared_ptr<U>& b) const noexcept; // (1) C++17
template <class U>
bool
owner_before(const weak_ptr<U>& b) const; // (2) C++11
template <class U>
bool
owner_before(const weak_ptr<U>& b) const noexcept; // (2) C++17
template <class U>
constexpr bool
owner_before(const weak_ptr<U>& b) const noexcept; // (2) C++26- shared_ptr[link /reference/memory/shared_ptr.md]
所有権ベースでの小なり比較を行う。
*thisが監視しているshared_ptrオブジェクトのリソースと、bが監視しているshared_ptrオブジェクトのリソースを、所有権ベースで小なり比較し、*thisが小さければtrue、そうでなければfalseを返す。
詳細は、shared_ptrのowner_before()メンバ関数を参照。
#include <iostream>
#include <memory>
struct X {
int i;
int j;
};
int main()
{
std::shared_ptr<X> org(new X());
std::shared_ptr<int> sa(org, &(org->i));
std::shared_ptr<int> sb(org, &(org->j));
std::weak_ptr<int> wa = sa;
std::weak_ptr<int> wb = sb;
bool ownership_based_result = wa.owner_before(wb); // wa and wb are equivalent
std::cout << std::boolalpha << ownership_based_result << std::endl;
}- owner_before[color ff0000]
false
- C++11
- GCC: 4.4.7 [mark verified]
- Clang: 3.0 [mark verified]
- ICC: ?
- Visual C++: ?