set::end
Restituisce un iteratore destinato alla posizione che è l'ultimo elemento al set.
const_iterator end( ) const;
iterator end( );
Valore restituito
Un iteratore bidirezionale destinato alla posizione che è l'ultimo elemento al set.Se il set è vuoto, quindi ==set::begin di set::end.
Note
end viene utilizzato per verificare se un iteratore raggiunge la fine del set.Il valore restituito da end non è possibile dereferenziare.
Esempio
// set_end.cpp
// compile with: /EHsc
#include <set>
#include <iostream>
int main( )
{
using namespace std;
set <int> s1;
set <int> :: iterator s1_Iter;
set <int> :: const_iterator s1_cIter;
s1.insert( 1 );
s1.insert( 2 );
s1.insert( 3 );
s1_Iter = s1.end( );
s1_Iter--;
cout << "The last element of s1 is " << *s1_Iter << endl;
s1.erase( s1_Iter );
// The following 3 lines would err because the iterator is const
// s1_cIter = s1.end( );
// s1_cIter--;
// s1.erase( s1_cIter );
s1_cIter = s1.end( );
s1_cIter--;
cout << "The last element of s1 is now " << *s1_cIter << endl;
}
Requisiti
intestazione: <set>
Spazio dei nomi: deviazione standard