[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/memory/shared_ptr/operator_cmp [Back]  [Original]

operator==, !=, <, <=, >, >=, <=> (std::shared_ptr) cppreference.com
cppreference.com

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

cppreference.com
 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
 
no section name
no section name
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)



no section name
 
 
<tbody> </tbody>
shared_ptr
template < class T, class U > bool operator==( const std::shared_ptr<T>& lhs, const std::shared_ptr<U>& rhs ) noexcept;
(1) ( C++11)
template< class T, class U > bool operator!=( const std::shared_ptr<T>& lhs, const std::shared_ptr<U>& rhs ) noexcept;
(2) ( C++11)
( C++20)
template< class T, class U > bool operator<( const std::shared_ptr<T>& lhs, const std::shared_ptr<U>& rhs ) noexcept;
(3) ( C++11)
( C++20)
template< class T, class U > bool operator>( const std::shared_ptr<T>& lhs, const std::shared_ptr<U>& rhs ) noexcept;
(4) ( C++11)
( C++20)
template< class T, class U > bool operator<=( const std::shared_ptr<T>& lhs, const std::shared_ptr<U>& rhs ) noexcept;
(5) ( C++11)
( C++20)
template< class T, class U > bool operator>=( const std::shared_ptr<T>& lhs, const std::shared_ptr<U>& rhs ) noexcept;
(6) ( C++11)
( C++20)
template< class T, class U > std::strong_ordering operator<=>( const std::shared_ptr<T>& lhs, const std::shared_ptr<U>& rhs ) noexcept;
(7) ( C++20)
shared_ptr
template< class T > bool operator==( const std::shared_ptr<T>& lhs, std::nullptr_t ) noexcept;
(8) ( C++11)
template< class T > bool operator==( std::nullptr_t, const std::shared_ptr<T>& rhs ) noexcept;
(9) ( C++11)
( C++20)
template< class T > bool operator!=( const std::shared_ptr<T>& lhs, std::nullptr_t ) noexcept;
(10) ( C++11)
( C++20)
template< class T > bool operator!=( std::nullptr_t, const std::shared_ptr<T>& rhs ) noexcept;
(11) ( C++11)
( C++20)
template< class T > bool operator<( const std::shared_ptr<T>& lhs, std::nullptr_t ) noexcept;
(12) ( C++11)
( C++20)
template< class T > bool operator<( std::nullptr_t, const std::shared_ptr<T>& rhs ) noexcept;
(13) ( C++11)
( C++20)
template< class T > bool operator>( const std::shared_ptr<T>& lhs, std::nullptr_t ) noexcept;
(14) ( C++11)
( C++20)
template< class T > bool operator>( std::nullptr_t, const std::shared_ptr<T>& rhs ) noexcept;
(15) ( C++11)
( C++20)
template< class T > bool operator<=( const std::shared_ptr<T>& lhs, std::nullptr_t ) noexcept;
(16) ( C++11)
( C++20)
template< class T > bool operator<=( std::nullptr_t, const std::shared_ptr<T>& rhs ) noexcept;
(17) ( C++11)
( C++20)
template< class T > bool operator>=( const std::shared_ptr<T>& lhs, std::nullptr_t ) noexcept;
(18) ( C++11)
( C++20)
template< class T > bool operator>=( std::nullptr_t, const std::shared_ptr<T>& rhs ) noexcept;
(19) ( C++11)
( C++20)
template< class T > std::strong_ordering operator<=>( const std::shared_ptr<T>& lhs, std::nullptr_t ) noexcept;
(20) ( C++20)

shared_ptr<T> shared_ptr<T> .

: shared_ptr ; , , . operator<, shared_ptr, shared_ptr , std::map std::set.

<, <=, >, >= != operator<=> operator== .

( C++20)

lhs shared_ptr
rhs shared_ptr

1) lhs.get() == rhs.get()
2) !(lhs == rhs)
3) std::less<V>()(lhs.get(), rhs.get()), V std::shared_ptr<T>::element_type* std::shared_ptr<U>::element_type*
4) rhs < lhs
5) !(rhs < lhs)
6) !(lhs < rhs)
7) std::compare_three_way{}(x.get(), y.get())
8) !lhs
9) !rhs
10) (bool)lhs
11) (bool)rhs
12) std::less<std::shared_ptr<T>::element_type*>()(lhs.get(), nullptr)
13) std::less<std::shared_ptr<T>::element_type*>()(nullptr, rhs.get())
14) nullptr < lhs
15) rhs < nullptr
16) !(nullptr < lhs)
17) !(rhs < nullptr)
18) !(lhs < nullptr)
19) !(nullptr < rhs)
20) std::compare_three_way{}(x.get(), static_cast<std::shared_ptr<T>::element_type*>(nullptr))

(, get()), (, , use_count ). shared_ptr, .

#include <iostream>
#include <memory>

int main()
{
    std::shared_ptr<int> p1(new int(42));
    std::shared_ptr<int> p2(new int(42));

    std::cout << std::boolalpha
        << "(p1 == p1)       : " << (p1 == p1) << '\n'
        << "(p1 <=> p1) == 0 : " << ((p1 <=> p1) == 0) << '\n' //   C++20

    // p1  p2     ,  p1 != p2
        << "(p1 == p2)       : " << (p1 == p2) << '\n'
        << "(p1 < p2)        : " << (p1 < p2) << '\n'
        << "(p1 <=> p2) < 0  : " << ((p1 <=> p2) < 0) << '\n'   //   C++20
        << "(p1 <=> p2) == 0 : " << ((p1 <=> p2) == 0) << '\n'; //   C++20
}

:

(p1 == p1)       : true
(p1 <=> p1) == 0 : true
(p1 == p2)       : false
(p1 < p2)        : true
(p1 <=> p2) < 0  : true
(p1 <=> p2) == 0 : false

C++:

LWG 3427 C++20 operator<=>(shared_ptr, nullptr_t)


(public -) []

Web Proxy Viewer  |  New URL  |  Original Page