| Iterator concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator primitives | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Algorithm concepts and utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Indirect callable concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Common algorithm requirements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
| Non-member functions | ||||
operator==operator!=operator<operator<=operator>operator>=operator<=> (C++20) | ||||
(C++20) | ||||
(C++20) | ||||
(C++14) |
Defined in header <iterator> | ||
template<class Iter1,class Iter2> bool operator==(conststd::reverse_iterator<Iter1>& lhs, | (1) | (constexpr since C++17) |
template<class Iter1,class Iter2> bool operator!=(conststd::reverse_iterator<Iter1>& lhs, | (2) | (constexpr since C++17) |
template<class Iter1,class Iter2> bool operator<(conststd::reverse_iterator<Iter1>& lhs, | (3) | (constexpr since C++17) |
template<class Iter1,class Iter2> bool operator<=(conststd::reverse_iterator<Iter1>& lhs, | (4) | (constexpr since C++17) |
template<class Iter1,class Iter2> bool operator>(conststd::reverse_iterator<Iter1>& lhs, | (5) | (constexpr since C++17) |
template<class Iter1,class Iter2> bool operator>=(conststd::reverse_iterator<Iter1>& lhs, | (6) | (constexpr since C++17) |
template<class Iter1,std::three_way_comparable_with<Iter1> Iter2> constexprstd::compare_three_way_result_t<Iter1, Iter2> | (7) | (since C++20) |
Compares the underlying iterators oflhs andrhs.
1) This overload participates in overload resolution only iflhs.base()== rhs.base() is well-formed and convertible tobool. 2) This overload participates in overload resolution only iflhs.base()!= rhs.base() is well-formed and convertible tobool. 3) This overload participates in overload resolution only iflhs.base()> rhs.base() is well-formed and convertible tobool. 4) This overload participates in overload resolution only iflhs.base()>= rhs.base() is well-formed and convertible tobool. 5) This overload participates in overload resolution only iflhs.base()< rhs.base() is well-formed and convertible tobool. 6) This overload participates in overload resolution only iflhs.base()<= rhs.base() is well-formed and convertible tobool. | (since C++20) |
Contents |
| lhs, rhs | - | iterator adaptors to compare |
operator<=> returnsrhs.base()<=> lhs.base() rather thanlhs.base()<=> rhs.base() because this is a reverse iterator.
#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 comparisonsassert( 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 comparisonsassert( x<=> y==0);assert(!(x<=> y<0));assert(!(x<=> y>0));assert(!(x<=> z==0));assert( x<=> z<0);assert(!(x<=> z>0));}
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 |