std::shared_ptr<T>::operator==,!=,<,<=,>,>= (3) - Linux Manuals
std::shared_ptr<T>::operator==,!=,<,<=,>,>=: std::shared_ptr<T>::operator==,!=,<,<=,>,>=
NAME
std::shared_ptr<T>::operator==,!=,<,<=,>,>= - std::shared_ptr<T>::operator==,!=,<,<=,>,>=
Synopsis
Compare two shared_ptr objects
template < class T, class U > (1) (since C++11)
bool operator==( const shared_ptr<T>& lhs, const shared_ptr<U>& rhs ) noexcept;
template< class T, class U > (2) (since C++11)
bool operator!=( const shared_ptr<T>& lhs, const shared_ptr<U>& rhs ) noexcept;
template< class T, class U > (3) (since C++11)
bool operator<( const shared_ptr<T>& lhs, const shared_ptr<U>& rhs ) noexcept;
template< class T, class U > (4) (since C++11)
bool operator>( const shared_ptr<T>& lhs, const shared_ptr<U>& rhs ) noexcept;
template< class T, class U > (5) (since C++11)
bool operator<=( const shared_ptr<T>& lhs, const shared_ptr<U>& rhs ) noexcept;
template< class T, class U > (6) (since C++11)
bool operator>=( const shared_ptr<T>& lhs, const shared_ptr<U>& rhs ) noexcept;
Compare a shared_ptr with a null pointer
template< class T > (7) (since C++11)
bool operator==( const shared_ptr<T>& lhs, std::nullptr_t rhs ) noexcept;
template< class T > (8) (since C++11)
bool operator==( std::nullptr_t lhs, const shared_ptr<T>& rhs ) noexcept;
template< class T > (9) (since C++11)
bool operator!=( const shared_ptr<T>& lhs, std::nullptr_t rhs ) noexcept;
template< class T > (10) (since C++11)
bool operator!=( std::nullptr_t lhs, const shared_ptr<T>& rhs ) noexcept;
template< class T > (11) (since C++11)
bool operator<( const shared_ptr<T>& lhs, std::nullptr_t rhs ) noexcept;
template< class T > (12) (since C++11)
bool operator<( std::nullptr_t lhs, const shared_ptr<T>& rhs ) noexcept;
template< class T > (13) (since C++11)
bool operator>( const shared_ptr<T>& lhs, std::nullptr_t rhs ) noexcept;
template< class T > (14) (since C++11)
bool operator>( std::nullptr_t lhs, const shared_ptr<T>& rhs ) noexcept;
template< class T > (15) (since C++11)
bool operator<=( const shared_ptr<T>& lhs, std::nullptr_t rhs ) noexcept;
template< class T > (16) (since C++11)
bool operator<=( std::nullptr_t lhs, const shared_ptr<T>& rhs ) noexcept;
template< class T > (17) (since C++11)
bool operator>=( const shared_ptr<T>& lhs, std::nullptr_t rhs ) noexcept;
template< class T > (18) (since C++11)
bool operator>=( std::nullptr_t lhs, const shared_ptr<T>& rhs ) noexcept;
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.
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 std::shared_ptr<T>::element_type* and std::shared_ptr<U>::element_type*
4) rhs < lhs
5) !(rhs < lhs)
6) !(lhs < rhs)
7) !lhs
8) !rhs
9) (bool)lhs
10) (bool)rhs
11) std::less<std::shared_ptr<T>::element_type*>()(lhs.get(), nullptr)
12) std::less<std::shared_ptr<T>::element_type*>()(nullptr, rhs.get())
13) nullptr < lhs
14) rhs < nullptr
15) !(nullptr < lhs)
16) !(rhs < nullptr)
17) !(lhs < nullptr)
18) !(nullptr < rhs)
Notes
In all cases, it is the stored pointer (the one returned by get()) that is compared, rather than the managed pointer (the one passed to the deleter when use_count goes to zero). The two pointers may differ in a shared_ptr created using the aliasing constructor.
Example
This section is incomplete
Reason: no example
See also
get (public member function)