hash_set::equal_range
[!メモ]
この API は、互換性のために残されています。代わりに unordered_set クラスです。
指定したキーとキーのハッシュのセットの最初の要素と同じキー、キーのハッシュのセットの最初の要素のペアの各反復子を返します。
pair <const_iterator, const_iterator> equal_range (
const Key& _Key
) const;
pair <iterator, iterator> equal_range (
const Key& _Key
);
パラメーター
- _Key
検索hash_setからの要素の並べ替えキーと比較される引数のキー。
戻り値
1番目のキーと2番目の lower_bound のペアの反復子はキーの upper_bound です。
ペアprの最初の反復子アクセスをメンバー関数には、を使用して prを呼び出します。first、および下限のない反復子を逆参照するには、* (pr。first)。pr ペアの2番目の反復子アクセスをメンバー関数には、を使用して prを呼び出します。second、その上位のバインドされた反復子を逆参照するには、* (pr。second)。
解説
Visual C++ .NET 2003では、<hash_map> と <hash_set> ヘッダー ファイルのメンバーはstdの名前空間に存在しなくなりましたが、ではなくstdextの名前空間に型。詳細については、「The stdext Namespace」を参照してください。
使用例
// hash_set_equal_range.cpp
// compile with: /EHsc
#include <hash_set>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
typedef hash_set<int> IntHSet;
IntHSet hs1;
hash_set <int> :: const_iterator hs1_RcIter;
hs1.insert( 10 );
hs1.insert( 20 );
hs1.insert( 30 );
pair <IntHSet::const_iterator, IntHSet::const_iterator> p1, p2;
p1 = hs1.equal_range( 20 );
cout << "The upper bound of the element with "
<< "a key of 20 in the hash_set hs1 is: "
<< *(p1.second) << "." << endl;
cout << "The lower bound of the element with "
<< "a key of 20 in the hash_set hs1 is: "
<< *(p1.first) << "." << endl;
// Compare the upper_bound called directly
hs1_RcIter = hs1.upper_bound( 20 );
cout << "A direct call of upper_bound( 20 ) gives "
<< *hs1_RcIter << "," << endl
<< "matching the 2nd element of the pair"
<< " returned by equal_range( 20 )." << endl;
p2 = hs1.equal_range( 40 );
// If no match is found for the key,
// both elements of the pair return end( )
if ( ( p2.first == hs1.end( ) ) && ( p2.second == hs1.end( ) ) )
cout << "The hash_set hs1 doesn't have an element "
<< "with a key greater than or equal to 40." << endl;
else
cout << "The element of hash_set hs1 with a key >= 40 is: "
<< *(p1.first) << "." << endl;
}
必要条件
ヘッダー: <hash_set>
名前空間: のstdext