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


hash_map::equal_range

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

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

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

pair <const_iterator, const_iterator> equal_range (
   const Key& _Key
) const;
pair <iterator, iterator> equal_range (
   const Key& _Key
);

Параметры

  • _Key
    Значение ключа аргумента для сравнения с ключ сортировки элемента из hash_map, в котором выполняется поиск.

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

Пара итераторов то, что первый lower_bound ключа и второго upper_bound ключа.

Получить доступ к первому итератор пары pr, возвращаемого функцией-членом, использует pr.first и разыменования итератор нижней границы, используйте * (pr.first).Доступ к второй итератор пары pr, возвращаемого функцией-членом, использует pr.second и разыменования итератор границы, используйте * (pr.second).

Заметки

В Visual C++ .NET 2003 <hash_map> элементы файлов заголовков и <hash_set> больше не находятся в пространстве имен std, но скорее перейти на пространство имен stdext.Дополнительные сведения см. в разделе Пространство имен stdext.

Пример

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

int main( )
{
   using namespace std;
   using namespace stdext;
   typedef hash_map <int, int> IntMap;
   IntMap hm1;
   hash_map <int, int> :: const_iterator hm1_RcIter;
   typedef pair <int, int> Int_Pair;

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

   pair <IntMap::const_iterator, IntMap::const_iterator> p1, p2;
   p1 = hm1.equal_range( 2 );

   cout << "The lower bound of the element with "
        << "a key of 2 in the hash_map hm1 is: "
        << p1.first -> second << "." << endl;

   cout << "The upper bound of the element with "
        << "a key of 2 in the hash_map hm1 is: "
        << p1.second -> second << "." << endl;

   // Compare the upper_bound called directly 
   hm1_RcIter = hm1.upper_bound( 2 );

   cout << "A direct call of upper_bound( 2 ) gives "
        << hm1_RcIter -> second << "," << endl
        << " matching the 2nd element of the pair"
        << " returned by equal_range( 2 )." << endl;

   p2 = hm1.equal_range( 4 );

   // If no match is found for the key,
   // both elements of the pair return end( )
   if ( ( p2.first == hm1.end( ) ) && ( p2.second == hm1.end( ) ) )
      cout << "The hash_map hm1 doesn't have an element "
             << "with a key less than 40." << endl;
   else
      cout << "The element of hash_map hm1 with a key >= 40 is: "
           << p1.first -> first << "." << endl;
}
  
  
  
  

Требования

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

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

См. также

Ссылки

hash_map Class

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