![]() |
---|
此 API 已过时。另一种方法是 unordered_multiset Class。 |
返回迭代器到一 hash_multiset 的第一个元素使用比指定的键大的密钥。
const_iterator upper_bound(
const Key& _Key
) const;
iterator upper_bound(
const Key& _Key
);
参数
- _Key
参数键与一个元素的排序关键字进行比较从要搜索的 hash_multiset 的。
返回值
迭代器 或 const_iterator 比参数键解决第一个元素位置在一 hash_multiset 与大的键或解决成功最后一个元素的位置。hash_multiset,如果与未作为项中。
备注
在 Visual C++ .NET 2003 中,<hash_map> 和 <hash_set> 标头文件的成员中不再标准,命名空间,而是将 stdext 命名空间。有关更多信息,请参见 stdext 命名空间。
示例
// hash_multiset_upper_bound.cpp
// compile with: /EHsc
#include <hash_set>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_multiset <int> hms1;
hash_multiset <int> :: const_iterator hms1_AcIter, hms1_RcIter;
hms1.insert( 10 );
hms1.insert( 20 );
hms1.insert( 30 );
hms1_RcIter = hms1.upper_bound( 20 );
cout << "The first element of hash_multiset hms1" << endl
<< " with a key greater than 20 is: "
<< *hms1_RcIter << "." << endl;
hms1_RcIter = hms1.upper_bound( 30 );
// If no match is found for the key, end( ) is returned
if ( hms1_RcIter == hms1.end( ) )
cout << "The hash_multiset hms1 doesn't have an element "
<< "\n with a key greater than 30." << endl;
else
cout << "The element of hash_multiset hms1"
<< "with a key > 40 is: "
<< *hms1_RcIter << "." << endl;
// An element at a specific ___location in the hash_multiset can be
// found by using a dereferenced iterator addressing the ___location
hms1_AcIter = hms1.begin( );
hms1_RcIter = hms1.upper_bound( *hms1_AcIter );
cout << "The first element of hms1\n with a key greater than "
<< endl << "that of the initial element of hms1 is: "
<< *hms1_RcIter << "." << endl;
}
要求
标头: <hash_set>
命名空间: stdext