Namespaces
Variants
Views
Actions

std::shared_ptr::operator==, !=, <, <=, >, >=

From cppreference.com
< cpp‎ | memory‎ | shared ptr
Revision as of 15:51, 2 November 2012 by P12bot (Talk | contribs)

 
 
 
 
 

Template:ddcl list begin <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template <class T, class U>
    bool operator==(const shared_ptr<T>& lhs, const shared_ptr<U>& rhs);
</td>

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template <class T, class U>
    bool operator!=(const shared_ptr<T>& lhs, const shared_ptr<U>& rhs);
</td>

<td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template <class T, class U>
    bool operator<(const shared_ptr<T>& lhs, const shared_ptr<U>& rhs);
</td>

<td > (3) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template <class T, class U>
    bool operator>(const shared_ptr<T>& lhs, const shared_ptr<U>& rhs);
</td>

<td > (4) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template <class T, class U>
    bool operator<=(const shared_ptr<T>& lhs, const shared_ptr<U>& rhs);
</td>

<td > (5) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template <class T, class U>
    bool operator>=(const shared_ptr<T>& lhs, const shared_ptr<U>& rhs);
</td>

<td > (6) </td> <td class="t-dcl-nopad"> </td> </tr>

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

<tr class="t-dcl ">

<td >
template <class T>
    bool operator==(const shared_ptr<T>& lhs, std::nullptr_t rhs);
</td>

<td > (7) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template <class T>
    bool operator==(std::nullptr_t lhs, const shared_ptr<T>& rhs);
</td>

<td > (8) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template <class T>
    bool operator!=(const shared_ptr<T>& lhs, std::nullptr_t rhs);
</td>

<td > (9) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template <class T>
    bool operator!=(std::nullptr_t lhs, const shared_ptr<T>& rhs);
</td>

<td > (10) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template <class T>
    bool operator<(const shared_ptr<T>& lhs, std::nullptr_t rhs);
</td>

<td > (11) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template <class T>
    bool operator<(std::nullptr_t lhs, const shared_ptr<T>& rhs);
</td>

<td > (12) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template <class T>
    bool operator<=(const shared_ptr<T>& lhs, std::nullptr_t rhs);
</td>

<td > (13) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template <class T>
    bool operator<=(std::nullptr_t lhs, const shared_ptr<T>& rhs);
</td>

<td > (14) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template <class T>
    bool operator>(const shared_ptr<T>& lhs, std::nullptr_t rhs);
</td>

<td > (15) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template <class T>
    bool operator>(std::nullptr_t lhs, const shared_ptr<T>& rhs);
</td>

<td > (16) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template <class T>
    bool operator>=(const shared_ptr<T>& lhs, std::nullptr_t rhs);
</td>

<td > (17) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template <class T>
    bool operator>=(std::nullptr_t lhs, const shared_ptr<T>& rhs);
</td>

<td > (18) </td> <td class="t-dcl-nopad"> </td> </tr>

Template:ddcl list end

Compares two shared_ptr<T> objects or compares shared_ptr<T> with a null pointer.

Note that the comparison operators for shared_ptr simply compare pointer values; the actual objects pointed to are not compared. Having operator< defined for shared_ptr allows shared_ptrs to be used as keys in associative containers, like std::map and std::set.

Contents

Parameters

lhs - the left-hand shared_ptr to compare
rhs - the right-hand shared_ptr to compare

Return value

1) lhs.get() == rhs.get()

2) !(lhs == rhs)

3) std::less<V>()(lhs.get(), rhs.get()), where V is the composite pointer type of T* and U*

4) rhs < lhs

5) !(rhs < lhs)

6) !(lhs < rhs)

7) !lhs

8) !rhs

9) (bool)lhs

10) (bool)rhs

11) std::less<T*>()(lhs.get(), nullptr)

12) std::less<T*>()(nullptr, rhs.get())

13) nullptr < lhs

14) rhs < nullptr

15) !(nullptr < lhs)

16) !(rhs < nullptr)

17) !(lhs < nullptr)

18) !(nullptr < rhs)

Exceptions

noexcept specification:  
noexcept
  

Example

See also

Template:cpp/memory/shared ptr/dcl list get