Namespaces
Variants
Views
Actions

operator==,!=,<,<=,>,>=(std::unique_ptr)

From cppreference.com
< cpp‎ | memory‎ | unique ptr
Revision as of 15:07, 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 T1, class D1, class T2, class D2>
bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
</td>

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

<tr class="t-dcl ">

<td >
template<class T1, class D1, class T2, class D2>
bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
</td>

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

<tr class="t-dcl ">

<td >
template<class T1, class D1, class T2, class D2>
bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
</td>

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

<tr class="t-dcl ">

<td >
template<class T1, class D1, class T2, class D2>
bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
</td>

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

<tr class="t-dcl ">

<td >
template<class T1, class D1, class T2, class D2>
bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
</td>

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

<tr class="t-dcl ">

<td >
template<class T1, class D1, class T2, class D2>
bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
</td>

<td > (6) </td> <td > (since C++11) </td> </tr>

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

<tr class="t-dcl ">

<td >
template <class T, class D>
bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
</td>

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

<tr class="t-dcl ">

<td >
template <class T, class D>
bool operator==(nullptr_t, const unique_ptr<T, D>& x) noexcept;
</td>

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

<tr class="t-dcl ">

<td >
template <class T, class D>
bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
</td>

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

<tr class="t-dcl ">

<td >
template <class T, class D>
bool operator!=(nullptr_t, const unique_ptr<T, D>& x) noexcept;
</td>

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

<tr class="t-dcl ">

<td >
template <class T, class D>
bool operator<(const unique_ptr<T, D>& x, nullptr_t);
</td>

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

<tr class="t-dcl ">

<td >
template <class T, class D>
bool operator<(nullptr_t, const unique_ptr<T, D>& y);
</td>

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

<tr class="t-dcl ">

<td >
template <class T, class D>
bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
</td>

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

<tr class="t-dcl ">

<td >
template <class T, class D>
bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
</td>

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

<tr class="t-dcl ">

<td >
template <class T, class D>
bool operator>(const unique_ptr<T, D>& x, nullptr_t);
</td>

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

<tr class="t-dcl ">

<td >
template <class T, class D>
bool operator>(nullptr_t, const unique_ptr<T, D>& y);
</td>

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

<tr class="t-dcl ">

<td >
template <class T, class D>
bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
</td>

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

<tr class="t-dcl ">

<td >
template <class T, class D>
bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
</td>

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

Compares the pointer values of two unique_ptrs, or a unique_ptr and nullptr.

Contents

Parameters

x, y - unique_ptrs to compare

Return value

1) x.get() == y.get()

2) x.get() != y.get()

3) std::less<CT>()(x.get(), y.get()), where CT is std::common_type<unique_ptr<T1, D1>::pointer, unique_ptr<T2, D2>::pointer>::type

4) !(y < x)

5) y < x

6) !(x < y)

7-8) !x

9-10) (bool)x

11) std::less<unique_ptr<T,D>::pointer>()(x.get(), nullptr)

12) std::less<unique_ptr<T,D>::pointer>()(nullptr, y.get())

13) nullptr < x

14) y < nullptr

15) !(nullptr < x)

16) !(y < nullptr)

17) !(x < nullptr)

18) !(nullptr < y)

Example

#include <iostream>
#include <memory>
 
int main() 
{
    std::unique_ptr<int> p1(new int(42));
    std::unique_ptr<int> p2(new int(42));
 
    std::cout << "p1 == p1: " << (p1 == p1) << '\n';
 
    // p1 and p2 point to different memory locations, so p1 != p2
    std::cout << "p1 == p2: " << (p1 == p2) << '\n';
}

Output:

p1 == p1: 1
p1 == p2: 0

See also

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