operator==,!=,<,<=,>,>=,<=>(std::reverse_iterator) - cppreference.com
From cppreference.com
| Defined in header |
||
|
(1) | (constexpr since C++17) |
|
(2) | (constexpr since C++17) |
|
(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.
- The result of equality comparisons are preserved (i.e. equal underlying iterators imply equal reverse iterators).
- The result of relational comparisons are reversed (i.e. a greater underlying iterator implies a lesser reverse iterator).
|
1) This overload participates in overload resolution only if 2) This overload participates in overload resolution only if 3) This overload participates in overload resolution only if 4) This overload participates in overload resolution only if 5) This overload participates in overload resolution only if 6) This overload participates in overload resolution only if |
(since C++20) |
Parameters
| lhs, rhs | - | iterator adaptors to compare |
Return value
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()
Notes
operator<=> returns rhs.base() <=> lhs.base() rather than lhs.base() <=> rhs.base() because this is a reverse iterator.
Example
#include <cassert> #include <iterator> int main() { int a[]{0, 1, 2, 3}; // ↑ └───── x, y // └──────── z // “x” and “y” are equal, but “x” is less than “z” (reversely) std::reverse_iterator<int*> x{std::rend(a) - std::size(a)}, y{std::rend(a) - std::size(a)}, z{std::rbegin(a) + 1}; // 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)); }
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 280 | C++98 | heterogeneous assignment was not allowed | allowed |