hash_multiset::equal_range

说明说明

此 API 已过时。另一种方法是 unordered_multiset Class

返回迭代器对分别对一 hash_multiset 的第一个元素使用比指定的键大的密钥以及在 hash_multiset 的第一个元素与等于或大于键的键。

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

参数

  • _Key
    参数键与一个元素的排序关键字进行比较从要搜索的 hash_multiset 的。

返回值

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

为对第一个迭代 pr 跟成员函数返回的访问,请使用 pr。第一个 和取消引用下限迭代器,使用* (pr。第一个)。为对第二个迭代 pr 跟成员函数返回的访问,请使用 pr。第二个 和取消引用上限迭代器,使用* (pr。第二个)。

在 Visual C++ .NET 2003 中,<hash_map><hash_set> 标头文件的成员中不再标准,命名空间,而是将 stdext 命名空间。有关更多信息,请参见 stdext 命名空间

示例

// hash_multiset_equal_range.cpp
// compile with: /EHsc
#include <hash_set>
#include <iostream>

int main( )
{
   using namespace std;
   using namespace stdext;
   typedef hash_multiset<int> IntHSet;
   IntHSet hms1;
   hash_multiset <int> :: const_iterator hms1_RcIter;
   
   hms1.insert( 10 );
   hms1.insert( 20 );
   hms1.insert( 30 );

   pair <IntHSet::const_iterator, IntHSet::const_iterator> p1, p2;
   p1 = hms1.equal_range( 20 );

   cout << "The upper bound of the element with "
        << "a key of 20\nin the hash_multiset hms1 is: "
        << *(p1.second) << "." << endl;

   cout << "The lower bound of the element with "
        << "a key of 20\nin the hash_multiset hms1 is: "
        << *(p1.first) << "." << endl;

   // Compare the upper_bound called directly 
   hms1_RcIter = hms1.upper_bound( 20 );
   cout << "A direct call of upper_bound( 20 ) gives "
        << *hms1_RcIter << "," << endl
        << "matching the 2nd element of the pair"
        << " returned by equal_range( 20 )." << endl;

   p2 = hms1.equal_range( 40 );

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

要求

标头: <hash_set>

命名空间: stdext

请参见

参考

hash_multiset Class

标准模板库