最終更新日時(UTC):
が更新

履歴 編集

function template
<memory>

std::weak_ptr::owner_before(C++11)

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>
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

概要

所有権ベースでの小なり比較を行う。

戻り値

*thisが監視しているshared_ptrオブジェクトのリソースと、bが監視しているshared_ptrオブジェクトのリソースを、所有権ベースで小なり比較し、*thisが小さければtrue、そうでなければfalseを返す。

詳細は、shared_ptrowner_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;
}

出力

false

バージョン

言語

  • C++11

処理系

関連項目

参照