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

来自cppreference.com
< cpp‎ | container‎ | list

template< class T, class Alloc >

bool operator==( const std::list<T,Alloc>& lhs,

                 const std::list<T,Alloc>& rhs );
(1)
template< class T, class Alloc >

bool operator!=( const std::list<T,Alloc>& lhs,

                 const std::list<T,Alloc>& rhs );
(2)
template< class T, class Alloc >

bool operator<( const std::list<T,Alloc>& lhs,

                const std::list<T,Alloc>& rhs );
(3)
template< class T, class Alloc >

bool operator<=( const std::list<T,Alloc>& lhs,

                 const std::list<T,Alloc>& rhs );
(4)
template< class T, class Alloc >

bool operator>( const std::list<T,Alloc>& lhs,

                const std::list<T,Alloc>& rhs );
(5)
template< class T, class Alloc >

bool operator>=( const std::list<T,Alloc>& lhs,

                 const std::list<T,Alloc>& rhs );
(6)

比较二个容器的内容。

1-2) 检查 lhsrhs 的内容是否相等,即它们是否拥有相同数量的元素且 lhs 中每个元素与 rhs 的同位置元素比较相等。
3-6) 按字典序比较 lhsrhs 的内容。由等价于 std::lexicographical_compare 的函数进行比较。

参数

lhs, rhs - 要比较内容的容器
-
为使用重载 (1-2) , T 必须满足可相等比较 (EqualityComparable) 的要求。
-
为使用重载 (3-6) , T 必须满足可小于比较 (LessThanComparable) 的要求。顺序关系必须建立全序。

返回值

1) 若容器内容相等则为 true ,否则为 false
2) 若容器内容不相等则为 true ,否则为 false
3)lhs 的内容按字典序小于 rhs 的内容则为 true ,否则为 false
4)lhs 的内容按字典序小于等于 rhs 的内容则为 true ,否则为 false
5)lhs 的内容按字典序大于 rhs 的内容则为 true ,否则为 false
6)lhs 的内容按字典序大于等于 rhs 的内容则为 true ,否则为 false

复杂度

1-2)lhsrhs 的大小不同则为常数,否则与容器大小成线性
3-6) 与容器大小成线性