hash_multimap::equal_range

备注

此 API 已过时。替代为 unordered_multimap 类

返回一个对迭代器分别到 hash_multimap 的第一个元素与大于指定的键的高一个键和为 hash_multimap 的第一个元素与大于或等于该的。

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

参数

  • _Key
    参数用键元素的排序关键字进行比较从搜索的 hash_multimap 的。

返回值

一对迭代器的第一和第二是 lower_bound 键是键的 upper_bound

若要访问受对 pr 的第一个迭代器由成员函数返回,则使用 pr。first 和取消引用更低限制的迭代器,使用* (pr。first)。 若要访问受对 pr 的第二个迭代器由成员函数返回,则使用 pr。 取消引用和上限的迭代器,使用* (pr。)。

备注

在Visual C++ .NET 2003中,成员<hash_map><hash_set> 头文件不再在std命名空间,而是已经进入了stdext命名空间。 有关更多信息,请参见 stdext 命名空间

示例

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

int main( )
{
   using namespace std;
   using namespace stdext;
   typedef hash_multimap <int, int> IntMMap;
   IntMMap hm1;
   hash_multimap <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 <IntMMap::const_iterator, IntMMap::const_iterator> p1, p2;
   p1 = hm1.equal_range( 2 );

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

   cout << "The upper bound of the element with "
        << "a key of 2\n in the hash_multimap 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_multimap hm1 doesn't have an element "
           << "with a key less than 4." << endl;
   else
      cout << "The element of hash_multimap hm1 with a key >= 40 is: "
           << p1.first -> first << "." << endl;
}
  

要求

标头: <hash_map>

**命名空间:**stdext

请参见

参考

hash_multimap 类

标准模板库