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