Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::owner_equal

      From cppreference.com
      <cpp‎ |memory
       
       
      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*)
      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)
       
      Defined in header<memory>
      struct owner_equal;
      (since C++26)

      This function object provides owner-based (as opposed to value-based) mixed-type equal comparison of bothstd::weak_ptr andstd::shared_ptr. The comparison is such that two smart pointers compare equivalent only if they are both empty or if they share ownership, even if the values of the raw pointers obtained byget() are different (e.g. because they point at different subobjects within the same object).

      1) Owner-based mixed-type equal comparison is not provided for types other thanstd::shared_ptr andstd::weak_ptr.
      2) The owner-based mixed-type equal comparison ofstd::shared_ptr andstd::weak_ptr.
      It is the preferred comparison predicate when building unordered associative containers withstd::shared_ptr andstd::weak_ptr as keys together withstd::owner_hash, that is,std::unordered_map<std::shared_ptr<T>, U, std::owner_hash, std::owner_equal> orstd::unordered_map<std::weak_ptr<T>, U, std::owner_hash, std::owner_equal>.
      3)std::owner_equal deduces the parameter types from the arguments.

      Contents

      [edit]Nested types

      Nested type Definition
      is_transparentunspecified

      [edit]Member functions

      operator()
      compares its arguments using owner-based semantics
      (function)

      std::owner_equal::operator()

      template<class T,class U>

      bool operator()(conststd::shared_ptr<T>& lhs,

                       conststd::shared_ptr<U>& rhs)constnoexcept;
      (since C++26)
      template<class T,class U>

      bool operator()(conststd::shared_ptr<T>& lhs,

                       conststd::weak_ptr<U>& rhs)constnoexcept;
      (since C++26)
      template<class T,class U>

      bool operator()(conststd::weak_ptr<T>& lhs,

                       conststd::shared_ptr<U>& rhs)constnoexcept;
      (since C++26)
      template<class T,class U>

      bool operator()(conststd::weak_ptr<T>& lhs,

                       conststd::weak_ptr<U>& rhs)constnoexcept;
      (since C++26)

      Compareslhs andrhs using owner-based semantics. Effectively callslhs.owner_equal(rhs).

      The equal comparison is an equivalence relation.

      lhs andrhs are equivalent only if they are both empty or share ownership.

      Parameters

      lhs, rhs - shared-ownership pointers to compare

      Return value

      true iflhs andrhs are both empty or share ownership as determined by the owner-based equal comparison,false otherwise.

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_smart_ptr_owner_equality202306L(C++26)Enabling the use ofstd::shared_ptr andstd::weak_ptr as keys inunordered associative containers

      [edit]See also

      provides owner-based equal comparison of shared pointers
      (public member function ofstd::shared_ptr<T>)[edit]
      provides owner-based equal comparison of weak pointers
      (public member function ofstd::weak_ptr<T>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/memory/owner_equal&oldid=168291"

      [8]ページ先頭

      ©2009-2025 Movatter.jp