deque::rbegin
Devuelve un iterador al primer elemento de un deque invertido.
const_reverse_iterator rbegin( ) const;
reverse_iterator rbegin( );
Valor devuelto
Un iterador de acceso aleatorio inversa que dirige el primer elemento de un deque o un direccionamiento invertido que había sido el último elemento del unreversed deque.
Comentarios
rbegin se utiliza con un deque invertido igual que inicio se utiliza con un deque.
Si el valor devuelto de rbegin se asigna a const_reverse_iterator, el objeto de deque no puede modificarse.Si el valor devuelto de rbegin se asigna a reverse_iterator, el objeto de deque puede modificarse.
rbegin se puede utilizar para iterar por un deque hacia atrás.
Ejemplo
// deque_rbegin.cpp
// compile with: /EHsc
#include <deque>
#include <iostream>
int main( )
{
using namespace std;
deque <int> c1;
deque <int>::iterator c1_Iter;
deque <int>::reverse_iterator c1_rIter;
// If the following line had replaced the line above, an error
// would have resulted in the line modifying an element
// (commented below) because the iterator would have been const
// deque <int>::const_reverse_iterator c1_rIter;
c1.push_back( 10 );
c1.push_back( 20 );
c1.push_back( 30 );
c1_rIter = c1.rbegin( );
cout << "Last element in the deque is " << *c1_rIter << "." << endl;
cout << "The deque contains the elements: ";
for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
cout << *c1_Iter << " ";
cout << "in that order.";
cout << endl;
// rbegin can be used to iterate through a deque in reverse order
cout << "The reversed deque is: ";
for ( c1_rIter = c1.rbegin( ); c1_rIter != c1.rend( ); c1_rIter++ )
cout << *c1_rIter << " ";
cout << endl;
c1_rIter = c1.rbegin( );
*c1_rIter = 40; // This would have caused an error if a
// const_reverse iterator had been declared as
// noted above
cout << "Last element in deque is now " << *c1_rIter << "." << endl;
}
Requisitos
encabezado: <deque>
espacio de nombres: std