hash_multiset::equal_range
[!メモ]
この API は、互換性のために残されています。代わりに unordered_multiset クラスです。
指定したキー、キーを持つ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からの要素の並べ替えキーと比較される引数のキー。
戻り値
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_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