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

比较二个 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 与空指针
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 起)

比较二个 shared_ptr<T> 对象或将 shared_ptr<T> 与空指针比较。

注意 shared_ptr 的比较运算符简单地比较指针值;比较所指向的实际对象。对 shared_ptr 定义 operator< 允许将 shared_ptr 用作关联容器,如 std::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)

注意

所有情况下,被比较者是存储的指针( get() 所返回者)而非被管理指针( uses_count 达到零时传递给删除器者)。二个指针可能在用别名使用构造函数创建的 shared_ptr 中不同。

示例

参阅

返回存储的指针
(公开成员函数)

版本历史

  • (当前 | 先前 2017年9月3日 (日) 19:44Fruderica讨论 | 贡献 . . (4,410字节) (-13). . (撤销)
  • 当前 | 先前 2017年9月3日 (日) 19:43Fruderica讨论 | 贡献. . (4,423字节) (-45). . (撤销)
  • 当前 | 先前 2014年10月26日 (日) 17:57P12bot讨论 | 贡献 . . (4,468字节) (0). . (Fix some translations) (撤销)
  • 当前 | 先前 2013年7月2日 (二) 09:07P12bot讨论 | 贡献 . . (4,468字节) (-269). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 14:52P12bot讨论 | 贡献 . . (4,737字节) (+337). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 03:40P12讨论 | 贡献 . . (4,400字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (4,400字节) (-56). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 14:55P12讨论 | 贡献 . . (4,456字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (4,456字节) (+4,456). . (Translated from the English version using Google Translate)