hash_map::upper_bound
[!メモ]
この API は、互換性のために残されています。代わりに unordered_map クラスです。
指定したキーよりも大きい値を持つキーとhash_mapの最初の要素への反復子を返します。
iterator upper_bound(
const Key& _Key
);
const_iterator upper_bound(
const Key& _Key
) const;
パラメーター
- _Key
検索hash_mapからの要素の並べ替えキーの値と比較される引数のキー値。
戻り値
引数のキー [iterator] より大きいか const_iterator 一致するキーにhash_mapにある最後の要素の次の場所を示すキーとhash_mapの要素の位置をアドレス、または。
戻り値が const_iteratorに割り当てられている場合、hash_mapのオブジェクトは変更できません。戻り値が **[iterator]**に割り当てられている場合、hash_mapのオブジェクトを変更することができます。
解説
Visual C++ .NET 2003では、<hash_map> と <hash_set> ヘッダー ファイルのメンバーはstdの名前空間に存在しなくなりましたが、ではなくstdextの名前空間に型。詳細については、「The stdext Namespace」を参照してください。
使用例
// hash_map_upper_bound.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1;
hash_map <int, int> :: const_iterator hm1_AcIter, hm1_RcIter;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 1, 10 ) );
hm1.insert ( Int_Pair ( 2, 20 ) );
hm1.insert ( Int_Pair ( 3, 30 ) );
hm1_RcIter = hm1.upper_bound( 2 );
cout << "The first element of hash_map hm1 with a key "
<< "greater than 2 is: "
<< hm1_RcIter -> second << "." << endl;
// If no match is found for the key, end is returned
hm1_RcIter = hm1. upper_bound ( 4 );
if ( hm1_RcIter == hm1.end( ) )
cout << "The hash_map hm1 doesn't have an element "
<< "with a key greater than 4." << endl;
else
cout << "The element of hash_map hm1 with a key > 4 is: "
<< hm1_RcIter -> second << "." << endl;
// The element at a specific location in the hash_map can be found
// using a dereferenced iterator addressing the location
hm1_AcIter = hm1.begin( );
hm1_RcIter = hm1. upper_bound ( hm1_AcIter -> first );
cout << "The 1st element of hm1 with a key greater than "
<< "that\n of the initial element of hm1 is: "
<< hm1_RcIter -> second << "." << endl;
}
必要条件
ヘッダー: <hash_map>
名前空間: のstdext