◐ Shell
clean mode source ↗

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

提供: cppreference.com

<tbody> </tbody>

2つの shared_ptr オブジェクトの比較

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

(1) (C++11以上)

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

(2) (C++11以上)

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

(3) (C++11以上)

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

(4) (C++11以上)

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

(5) (C++11以上)

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

(6) (C++11以上)

shared_ptr とNULLポインタの比較

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

(7) (C++11以上)

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

(8) (C++11以上)

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

(9) (C++11以上)

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

(10) (C++11以上)

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

(11) (C++11以上)

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

(12) (C++11以上)

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

(13) (C++11以上)

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

(14) (C++11以上)

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

(15) (C++11以上)

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

(16) (C++11以上)

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

(17) (C++11以上)

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

(18) (C++11以上)

2つの shared_ptr<T> オブジェクトを比較、または shared_ptr<T> とヌルポインタを比較します。

shared_ptr に対する比較は単純にポインタ値を比較することに注意してください。 指されている実際のオブジェクトは比較されませんshared_ptr に対する operator< が定義されているため、 shared_ptrstd::mapstd::set などの連想コンテナでキーとして使用することができます。

引数

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) !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)

ノート

すべての場合において、比較されるのは管理対象オブジェクト (use_count がゼロに達したときデリータに渡されるもの) ではなく、格納されているポインタ (get() で返されるもの) です。 エイリアシングコンストラクタを使用して shared_ptr が作成された場合、2つのポインタは異なるかもしれません。

関連項目