operator==,!=,<,<=,>,>=,<=>(std::move_iterator)
来自cppreference.com
| 在标头 <iterator> 定义
|
||
template< class Iter1, class Iter2 > bool operator==( const std::move_iterator<Iter1>& lhs, const std::move_iterator<Iter2>& rhs ); |
(1) | (C++17 起为 constexpr) |
template< class Iter1, class Iter2 > bool operator!=( const std::move_iterator<Iter1>& lhs, const std::move_iterator<Iter2>& rhs ); |
(2) | (C++17 起为 constexpr) (C++20 前) |
template< class Iter1, class Iter2 > bool operator< ( const std::move_iterator<Iter1>& lhs, const std::move_iterator<Iter2>& rhs ); |
(3) | (C++17 起为 constexpr) |
template< class Iter1, class Iter2 > bool operator<=( const std::move_iterator<Iter1>& lhs, const std::move_iterator<Iter2>& rhs ); |
(4) | (C++17 起为 constexpr) |
template< class Iter1, class Iter2 > bool operator> ( const std::move_iterator<Iter1>& lhs, const std::move_iterator<Iter2>& rhs ); |
(5) | (C++17 起为 constexpr) |
template< class Iter1, class Iter2 > bool operator>=( const std::move_iterator<Iter1>& lhs, const std::move_iterator<Iter2>& rhs ); |
(6) | (C++17 起为 constexpr) |
template< class Iter1, std::three_way_comparable_with<Iter1> Iter2 > constexpr std::compare_three_way_result_t<Iter1, Iter2> operator<=>( const std::move_iterator<Iter1>& lhs, const std::move_iterator<Iter2>& rhs ); |
(7) | (C++20 起) |
比较 lhs 与 rhs 的底层迭代器。
|
1) 此重载只有在
lhs.base() == rhs.base() 良构并且可转换到 bool 时才会参与重载决议。3-6) 此重载只有在
lhs.base() < rhs.base() 良构并且可转换到 bool 时才会参与重载决议。
|
(C++20 起) |
参数
| lhs, rhs | - | 要比较的迭代器适配器 |
返回值
1)
lhs.base() == rhs.base()2)
lhs.base() != rhs.base()3)
lhs.base() > rhs.base()4)
lhs.base() >= rhs.base()5)
lhs.base() < rhs.base()6)
lhs.base() <= rhs.base()7)
rhs.base() <=> lhs.base()示例
运行此代码
#include <cassert>
#include <iterator>
int main()
{
int a[]{9, 8, 7, 6};
// │ └───── x, y
// └──────── z
// “x” 与 “y” 相等,但 “x” 大于 “z”
std::move_iterator<int*>
x{std::end(a) - 1},
y{std::end(a) - 1},
z{std::end(a) - 2};
// 双路比较
assert( x == y );
assert(!(x != y));
assert(!(x < y));
assert( x <= y );
assert(!(x == z));
assert( x != z );
assert(!(x < z));
assert(!(x <= z));
// 三路比较
assert( x <=> y == 0 );
assert(!(x <=> y < 0));
assert(!(x <=> y > 0));
assert(!(x <=> z == 0));
assert(!(x <=> z < 0));
assert( x <=> z > 0 );
}
参阅
| 比较底层迭代器与底层哨位 (函数模板) |