< cpp‎ | memory
Revision as of 16:47, 2 November 2012 by P12bot (Talk | contribs)


Template:ddcl list begin <tr class="t-dsc-header">

Defined in header <memory>

<td></td> <td></td> </tr> <tr class="t-dcl ">

<td >
template< class T >
struct owner_less; /* undefined */

<td > (1) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< class T >
struct owner_less<std::shared_ptr<T>>;

<td > (2) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< class T >
struct owner_less<std::weak_ptr<T>>;

<td > (3) </td> <td > (since C++11) </td> </tr> Template:ddcl list end

This function object provides owner-based (as opposed to value-based) mixed-type ordering of both std::weak_ptr and std::shared_ptr. The order is such that two smart pointers compare equivalent only if they are both empty or if they both manage the same object, 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)

This class template is the preferred comparison predicate when building associative containers with std::shared_ptr or std::weak_ptr as keys, that is,

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

The default operator< is not defined for weak pointers, and may wrongly consider two shared pointers for the same object non-equivalent (see shared_ptr::owner_before)

Member types

Member type Definition
result_type bool
first_argument_type 1) T
2) std::shared_ptr<T>
3) std::weak_ptr<T>
second_argument_type 1) T
2) std::shared_ptr<T>
3) std::weak_ptr<T>

Member functions

compares its arguments using owner-based semantics

See also

Template:cpp/memory/shared ptr/dcl list owner before