operator==,!=,<,<=,>,>=,<=>(std::move_iterator) - cppreference.com
From cppreference.com
| Defined in header |
||
|
(1) | (constexpr since C++17) |
|
(2) | (constexpr since C++17) (until C++20) |
|
(3) | (constexpr since C++17) |
|
(4) | (constexpr since C++17) |
|
(5) | (constexpr since C++17) |
|
(6) | (constexpr since C++17) |
|
|
(7) | (since C++20) |
Compares the underlying iterators of lhs and rhs.
|
1) This overload participates in overload resolution only if 3-6) These overloads participate in overload resolution only if The |
(since C++20) |
Parameters
| lhs, rhs | - | iterator adaptors to compare |
Return value
1) lhs.base() == rhs.base()
2) !(lhs == rhs)
3) lhs.base() < rhs.base()
4) !(rhs < lhs)
5) rhs < lhs
6) !(lhs < rhs)
7) lhs.base() <=> rhs.base()
Example
#include <cassert> #include <iterator> int main() { int a[]{9, 8, 7, 6}; // │ └───── x, y // └──────── z // “x” and “y” are equal, but “x” is greater than “z” std::move_iterator<int*> x{std::end(a) - 1}, y{std::end(a) - 1}, z{std::end(a) - 2}; // two-way comparisons assert( x == y ); assert(!(x != y)); assert(!(x < y)); assert( x <= y ); assert(!(x == z)); assert( x != z ); assert(!(x < z)); assert(!(x <= z)); // three-way comparisons assert( x <=> y == 0 ); assert(!(x <=> y < 0)); assert(!(x <=> y > 0)); assert(!(x <=> z == 0)); assert(!(x <=> z < 0)); assert( x <=> z > 0 ); }