std::reverse_iterator<Iter>::operator=

Assigns other.current to current.

# Declarations

template< class U >
reverse_iterator& operator=( const reverse_iterator<U>& other );

(constexpr since C++17)

# Parameters

# Return value

*this

# Example

#include <iostream>
#include <iterator>
 
int main()
{
    const int a1[]{0, 1, 2};
    int a2[]{0, 1, 2, 3};
    short a3[]{40, 41, 42};
 
    std::reverse_iterator<const int*> it1{std::crbegin(a1)};
    it1 = std::reverse_iterator<int*>{std::rbegin(a2)};   // OK
//  it1 = std::reverse_iterator<short*>{std::rbegin(a3)}; // Compilation error:
                                                          // incompatible pointer types
    std::reverse_iterator<const short*> it2{nullptr};
    it2 = std::rbegin(a3); // OK
//  it2 = std::begin(a3);  // Compilation error: no viable operator= overload
    std::cout << *it2 << '\n';
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 280C++98heterogeneous assignment was not allowedallowed
LWG 3435C++20the converting assignment operator was not constrainedconstrained

# See also