hash_map::equal_range

注意事項注意事項

這個 API 已經過時。這個選項是 unordered_map Class

傳回一組 Iterator 分別到 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 的。

傳回值

一組 Iterator 這類第一是 lower_bound 索引鍵和第二個是索引鍵的 upper_bound

若要存取一組 pr 的第一個 Iterator 的成員函式傳回,使用 pr。first 和取值下限 Iterator,使用* (pr。first)。若要存取一組 pr 的第二個 Iterator 由成員函式傳回,使用 pr。second 和取值上限 Iterator,使用* (pr。second)。

備註

在 Visual C++ .NET Pocket PC, <hash_map><hash_set> 標頭檔 (Header File) 的成員不在 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

標準樣板程式庫