Поделиться через


hash_map::end

ПримечаниеПримечание

Этот API устарел.Альтернативы unordered_map Class.

Возвращает итератор, который решает расположение преуспевая последний элемент в hash_map.

const_iterator end( ) const; 
iterator end( );

Возвращаемое значение

Двунаправленный итератор, который соответствует расположение преуспевая последний элемент в hash_map.Если hash_map пусто, то hash_map::begin == hash_map::end.

Заметки

end используется для проверки достиг конца hash_map ли итератор.

Значение, возвращаемое end не должно быть разыменоватьо.

Пример

// hash_map_end.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>

int main( ) 
{
   using namespace std;
   using namespace stdext;
   hash_map <int, int> hm1;

   hash_map <int, int> :: iterator hm1_Iter;
   hash_map <int, int> :: const_iterator hm1_cIter;
   typedef pair <int, int> Int_Pair;

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

   hm1_cIter = hm1.end( );
   hm1_cIter--;
   cout << "The value of last element of hm1 is " 
        << hm1_cIter -> second << "." << endl;
   
   hm1_Iter = hm1.end( );
   hm1_Iter--;
   hm1.erase ( hm1_Iter );

   // The following 2 lines would err because the iterator is const
   // hm1_cIter = hm1.end ( );
   // hm1_cIter--;
   // hm1.erase ( hm1_cIter );

   hm1_cIter = hm1.end( );
   hm1_cIter--;
   cout << "The value of last element of hm1 is now "
        << hm1_cIter -> second << "." << endl;
}
  
  

Требования

заголовок: <hash_map>

Stdext пространство имен:

См. также

Ссылки

hash_map Class

Стандартная библиотека шаблонов