hash_set::count
[!メモ]
この API は、互換性のために残されています。代わりに unordered_set クラスです。
キーがパラメーター指定したキーに一致するhash_setの要素数を返します。
size_type count(
const Key& _Key
) const;
パラメーター
- _Key
hash_setに一致する要素のキー。
戻り値
hash_setが並べ替えキーがパラメーターのキーに一致する要素が含まれている場合は1。
hash_setは、一致するキーを持つ要素がない場合は0。
解説
このメンバー関数は、次の範囲内の要素数を返します:
[lower_bound (_Key ), upper_bound (_Key ) ).
Visual C++ .NET 2003では、<hash_map> と <hash_set> ヘッダー ファイルのメンバーはstdの名前空間に存在しなくなりましたが、ではなくstdextの名前空間に型。詳細については、「The stdext Namespace」を参照してください。
使用例
/Wp64 フラグを持つまたは64ビット プラットフォームでこの例をコンパイルすると、コンパイラの警告C4267エラーが生成されます。この警告の詳細については、コンパイラの警告 (レベル 3) C4267を参照してください。
// hash_set_count.cpp
// compile with: /EHsc
#include <hash_set>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_set<int> hs1;
hash_set<int>::size_type i;
hs1.insert(1);
hs1.insert(1);
// Keys must be unique in hash_set, so duplicates are ignored.
i = hs1.count(1);
cout << "The number of elements in hs1 with a sort key of 1 is: "
<< i << "." << endl;
i = hs1.count(2);
cout << "The number of elements in hs1 with a sort key of 2 is: "
<< i << "." << endl;
}
必要条件
ヘッダー: <hash_set>
名前空間: のstdext