Sdílet prostřednictvím


hash_map::equal_range

[!POZNÁMKA]

Toto rozhraní API je zastaralé.Alternativou je unordered_map – třída.

Vrátí funkce pár iterátorů první prvek v hash_map s klíčem, který je větší než zadaný klíč a na první prvek v hash_map s klíčem, který je roven nebo větší než klíč.

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

Parametry

  • _Key
    Hodnota argumentu klíče porovnat s klíčem řazení prvek z hash_map hledání.

Vrácená hodnota

Pár iterátorů tak, že první je lower_bound klíče a druhý je upper_bound klíče.

První iterace dvojice přístup k pr vrácený členskou funkcí, používají pr. první a přistoupit přes ukazatel iterátor dolní mez, pomocí * (pr.první).Přístup k druhé iteraci páru pr vrácený členskou funkcí, používají pr. druhé a přistoupit přes ukazatel iterátor horní mez, pomocí * (pr.druhý).

Poznámky

V aplikaci Visual C++ .NET 2003, členové hlavičkových souborů tříd <hash_map> a <hash_set> již nejsou v oboru názvů std, ale byly přesunuty do oboru názvů stdext.Další informace naleznete v tématu Obor názvů stdext.

Příklad

// 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;
}
  

Požadavky

Hlavička: <hash_map>

Obor názvů: stdext

Viz také

Referenční dokumentace

hash_map – třída

Standardní knihovna šablon