operator==,!=,<,<=,>,>=,<=>(std::move_iterator)
来自cppreference.com
< cpp | iterator | move iterator
在标头 <iterator> 定义 | ||
template<class Iter1, class Iter2 > bool operator==(conststd::move_iterator<Iter1>& lhs, | (1) | (C++17 起为 constexpr ) |
template<class Iter1, class Iter2 > bool operator!=(conststd::move_iterator<Iter1>& lhs, | (2) | (C++17 起为 constexpr )(C++20 前) |
template<class Iter1, class Iter2 > bool operator<(conststd::move_iterator<Iter1>& lhs, | (3) | (C++17 起为 constexpr ) |
template<class Iter1, class Iter2 > bool operator<=(conststd::move_iterator<Iter1>& lhs, | (4) | (C++17 起为 constexpr ) |
template<class Iter1, class Iter2 > bool operator>(conststd::move_iterator<Iter1>& lhs, | (5) | (C++17 起为 constexpr ) |
template<class Iter1, class Iter2 > bool operator>=(conststd::move_iterator<Iter1>& lhs, | (6) | (C++17 起为 constexpr ) |
template<class Iter1, std::three_way_comparable_with<Iter1> Iter2 > constexprstd::compare_three_way_result_t<Iter1, Iter2> | (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);}
[编辑]参阅
比较底层迭代器与底层哨位 (函数模板) |