multiset::equal_range
指定したキー、キーと複数のセットの最初の要素と等しいか、キー、キーと複数のセットの最初の要素のペアの各反復子を返します。
pair <const_iterator, const_iterator>
equal_range (
const Key& _Key
) const;
pair <iterator, iterator>
equal_range (
const Key& _Key
);
パラメーター
- _Key
検索された複数の要素の並べ替えキーと比較される引数のキー。
戻り値
1 番目のキーと 2 番目の lower_bound であることを示す反復子のペアはクラスであるためのキー upper_bound です。
ペア pr の最初の反復子アクセスをメンバー関数には、を使用して prを呼び出します。first、および下限のない反復子を逆参照するには、* (pr。first)。pr ペアの 2 番目の反復子アクセスをメンバー関数には、を使用して prを呼び出します。second、その上位のバインドされた反復子を逆参照するには、* (pr。second)。
使用例
// multiset_equal_range.cpp
// compile with: /EHsc
#include <set>
#include <iostream>
int main( )
{
using namespace std;
typedef multiset<int, less<int> > IntSet;
IntSet ms1;
multiset <int> :: const_iterator ms1_RcIter;
ms1.insert( 10 );
ms1.insert( 20 );
ms1.insert( 30 );
pair <IntSet::const_iterator, IntSet::const_iterator> p1, p2;
p1 = ms1.equal_range( 20 );
cout << "The upper bound of the element with "
<< "a key of 20 in the multiset ms1 is: "
<< *( p1.second ) << "." << endl;
cout << "The lower bound of the element with "
<< "a key of 20 in the multiset ms1 is: "
<< *( p1.first ) << "." << endl;
// Compare the upper_bound called directly
ms1_RcIter = ms1.upper_bound( 20 );
cout << "A direct call of upper_bound( 20 ) gives "
<< *ms1_RcIter << "," << endl
<< "matching the 2nd element of the pair"
<< " returned by equal_range( 20 )." << endl;
p2 = ms1.equal_range( 40 );
// If no match is found for the key,
// both elements of the pair return end( )
if ( ( p2.first == ms1.end( ) ) && ( p2.second == ms1.end( ) ) )
cout << "The multiset ms1 doesn't have an element "
<< "with a key less than 40." << endl;
else
cout << "The element of multiset ms1 with a key >= 40 is: "
<< *( p1.first ) << "." << endl;
}
必要条件
ヘッダー: <set>
名前空間: std