Condividi tramite


multimap::rend

Restituisce un iteratore destinato alla posizione che è l'ultimo elemento a multimap invertito.

const_reverse_iterator rend( ) const; 
reverse_iterator rend( );

Valore restituito

Un iteratore bidirezionale inverso destinato alla posizione che è l'ultimo elemento a multimap inverso (la posizione che aveva precedente il primo elemento in multimap unreversed).

Note

rend viene utilizzato con un multimap invertito come fine viene utilizzato con un multimap.

Se il valore restituito rend viene assegnato a const_reverse_iterator, l'oggetto di multimap non può essere modificato.Se il valore restituito rend viene assegnato a reverse_iterator, l'oggetto di multimap può essere modificato.

rend può essere utilizzato per verificare se un iteratore inverso raggiunge la fine del relativo multimap.

Il valore restituito da rend non è possibile dereferenziare.

Esempio

// multimap_rend.cpp
// compile with: /EHsc
#include <map>
#include <iostream>

int main( )
{
   using namespace std;
   multimap <int, int> m1;

   multimap <int, int> :: iterator m1_Iter;
   multimap <int, int> :: reverse_iterator m1_rIter;
   multimap <int, int> :: const_reverse_iterator m1_crIter;
   typedef pair <int, int> Int_Pair;

   m1.insert ( Int_Pair ( 1, 10 ) );
   m1.insert ( Int_Pair ( 2, 20 ) );
   m1.insert ( Int_Pair ( 3, 30 ) );

   m1_rIter = m1.rend( );
   m1_rIter--;
   cout << "The last element of the reversed multimap m1 is "
        << m1_rIter -> first << "." << endl;

   // begin can be used to start an iteration 
   // throught a multimap in a forward order
   cout << "The multimap is: ";
   for ( m1_Iter = m1.begin( ) ; m1_Iter != m1.end( ); m1_Iter++)
      cout << m1_Iter -> first << " ";
      cout << "." << endl;

   // rbegin can be used to start an iteration 
   // throught a multimap in a reverse order
   cout << "The reversed multimap is: ";
   for ( m1_rIter = m1.rbegin( ) ; m1_rIter != m1.rend( ); m1_rIter++)
      cout << m1_rIter -> first << " ";
      cout << "." << endl;

   // A multimap element can be erased by dereferencing to its key 
   m1_rIter = --m1.rend( );
   m1.erase ( m1_rIter -> first );

   m1_rIter = m1.rend( );
   m1_rIter--;
   cout << "After the erasure, the last element "
        << "in the reversed multimap is "
        << m1_rIter -> first << "." << endl;
}
  
  
  
  

Requisiti

intestazione: <map>

Spazio dei nomi: deviazione standard

Vedere anche

Riferimenti

multimap Class

Libreria di modelli standard