table of contents
        
      
      
    | std::owner_equal(3) | C++ Standard Libary | std::owner_equal(3) | 
NAME¶
std::owner_equal - std::owner_equal
Synopsis¶
 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 both std::weak_ptr and std::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 by get() 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
    than
  
   std::shared_ptr and std::weak_ptr.
  
   2) The owner-based mixed-type equal comparison of std::shared_ptr and
    std::weak_ptr.
  
   It is the preferred comparison predicate when building unordered associative
  
   containers with std::shared_ptr and std::weak_ptr as keys together with
  
   std::owner_hash, that is, std::unordered_map<std::shared_ptr<T>, U,
    std::owner_hash,
  
   std::owner_equal> or std::unordered_map<std::weak_ptr<T>, U,
    std::owner_hash,
  
   std::owner_equal>.
  
   3) std::owner_equal deduces the parameter types from the arguments.
Member functions¶
 operator() compares its arguments using owner-based semantics
  
   (function)
std::owner_equal::operator()
  
   template< class T, class U >
  
   bool operator()( const std::shared_ptr<T>& lhs, (since C++26)
  
   const std::shared_ptr<U>& rhs ) const noexcept;
  
   template< class T, class U >
  
   bool operator()( const std::shared_ptr<T>& lhs, (since C++26)
  
   const std::weak_ptr<U>& rhs ) const noexcept;
  
   template< class T, class U >
  
   bool operator()( const std::weak_ptr<T>& lhs, (since C++26)
  
   const std::shared_ptr<U>& rhs ) const noexcept;
  
   template< class T, class U >
  
   bool operator()( const std::weak_ptr<T>& lhs, (since C++26)
  
   const std::weak_ptr<U>& rhs ) const noexcept;
  
   Compares lhs and rhs using owner-based semantics. Effectively calls
  
   lhs.owner_equal(rhs).
  
   The equal comparison is an equivalence relation.
  
   lhs and rhs are equivalent only if they are both empty or share
  ownership.
Parameters¶
lhs, rhs - shared-ownership pointers to compare
Return value¶
 true if lhs and rhs are both empty or share ownership as
    determined by the
  
   owner-based equal comparison, false otherwise.
Notes¶
 Feature-test macro Value Std Feature
  
   Enabling the use of
  
   __cpp_lib_smart_ptr_owner_equality 202306L (C++26) std::shared_ptr and
    std::weak_ptr
  
   as keys in unordered associative
  
   containers
See also¶
 owner_equal provides owner-based equal comparison of shared
    pointers
  
   (C++26) (public member function of std::shared_ptr<T>)
  
   owner_equal provides owner-based equal comparison of weak pointers
  
   (C++26) (public member function of std::weak_ptr<T>)
| 2024.06.10 | http://cppreference.com |