hash_multimap (STL/CLR)

このテンプレート クラスは、双方向にアクセスできる可変長の要素シーケンスを制御するオブジェクトを表します。 hash_multimap コンテナーを使って、要素のシーケンスをハッシュ テーブルとして管理します。各テーブル エントリにはノードの双方向リンク リストが格納され、各ノードには 1 つの要素が格納されます。 要素は、シーケンスを順序付けるためのキーと、マップされた値で構成されていて、これらは一緒に移動します。

以降の説明では、GValue は次と同じです。

Microsoft::VisualC::StlClr::GenericPair<GKey, GMapped>

どこで:

GKey は、後者が ref 型でない限り同じです Key が、その場合は Key^

GMapped は、後者が ref 型でない限り同じです Mapped が、その場合は Mapped^

構文

template<typename Key,
    typename Mapped>
    ref class hash_multimap
        :   public
        System::ICloneable,
        System::Collections::IEnumerable,
        System::Collections::ICollection,
        System::Collections::Generic::IEnumerable<GValue>,
        System::Collections::Generic::ICollection<GValue>,
        System::Collections::Generic::IList<GValue>,
        Microsoft::VisualC::StlClr::IHash<Gkey, GValue>
    { ..... };

パラメーター

Key
制御シーケンス内の要素のキー コンポーネントの型。

Mapped
制御シーケンス内の要素の他のコンポーネントの型。

必要条件

ヘッダー:<cliext/hash_map>

名前空間cliext:

宣言

型定義 説明
hash_multimap::const_iterator 被制御シーケンスの定数反復子の型です。
hash_multimap::const_reference 要素への定数参照の型です。
hash_multimap::const_reverse_iterator 被制御シーケンスの定数反転反復子の型です。
hash_multimap::difference_type 2 つの要素間の距離を表す (場合によっては符号付きの) 型です。
hash_multimap::generic_container コンテナーのジェネリック インターフェイスの型です。
hash_multimap::generic_iterator コンテナーのジェネリック インターフェイスの反復子の型です。
hash_multimap::generic_reverse_iterator コンテナーのジェネリック インターフェイスの反転反復子の型です。
hash_multimap::generic_value コンテナーのジェネリック インターフェイスの要素の型です。
hash_multimap::hasher キーのハッシュ デリゲートです。
hash_multimap::iterator 被制御シーケンスの反復子の型です。
hash_multimap::key_compare 2 つのキーの順序付けデリゲートです。
hash_multimap::key_type 順序付けキーの型です。
hash_multimap::mapped_type 各キーに関連付けられた、マップされた値の型です。
hash_multimap::reference 要素への参照の型です。
hash_multimap::reverse_iterator 被制御シーケンスの反転反復子の型です。
hash_multimap::size_type 2 つの要素間の距離を表す (負でない) 型です。
hash_multimap::value_compare 2 つの要素値の順序付けデリゲートです。
hash_multimap::value_type 要素の型。
メンバー関数 説明
hash_multimap::begin 被制御シーケンスの先頭を指定します。
hash_multimap::bucket_count バケット数をカウントします。
hash_multimap::clear すべての要素を削除します。
hash_multimap::count 指定したキーに一致する要素をカウントします。
hash_multimap::empty 要素が存在しないかどうかをテストします。
hash_multimap::end 被制御シーケンスの末尾を指定します。
hash_multimap::equal_range 指定したキーに一致する範囲を検索します。
hash_multimap::erase 指定した位置にある要素を削除します。
hash_multimap::find 指定したキーに一致する要素を検索します。
hash_multimap::hash_delegate キーのハッシュ デリゲートをコピーします。
hash_multimap::hash_multimap コンテナー オブジェクトを構築します。
hash_multimap::insert 要素を追加します。
hash_multimap::key_comp 2 つのキーの順序付けデリゲートをコピーします。
hash_multimap::load_factor バケットごとの平均要素数をカウントします。
hash_multimap::lower_bound 指定したキーに一致する範囲の先頭を検索します。
hash_multimap::make_value 値オブジェクトを構築します。
hash_multimap::max_load_factor バケットあたりの最大要素数を取得または設定します。
hash_multimap::rbegin 反転被制御シーケンスの先頭を指定します。
hash_multimap::rehash ハッシュ テーブルをリビルドします。
hash_multimap::rend 反転被制御シーケンスの末尾を指定します。
hash_multimap::size 要素の数をカウントします。
hash_multimap::swap 2 つのコンテナーのコンテンツを交換します。
hash_multimap::to_array 被制御シーケンスを新しい配列にコピーします。
hash_multimap::upper_bound 指定したキーに一致する範囲の末尾を検索します。
hash_multimap::value_comp 2 つの要素値の順序付けデリゲートをコピーします。
Operator 説明
hash_multimap::operator= 被制御シーケンスを置き換えます。

インターフェイス

インターフェイス 説明
ICloneable オブジェクトを複製します。
IEnumerable 要素をシーケンス処理します。
ICollection 要素のグループを維持します。
IEnumerable<T> 型指定された要素をシーケンス処理します。
ICollection<T> 型指定された要素のグループを維持します。
IHash<Key, Value> ジェネリック コンテナーを維持します。

解説

このオブジェクトでは、双方向リンク リスト内の個々のノードとしての被制御シーケンスに対してストレージの割り当てと解放を行います。 アクセスを高速化するために、このオブジェクトは可変長のポインターの配列をリスト (ハッシュ テーブル) にも保持し、リスト全体をサブリスト (バケット) のシーケンスとして効果的に管理します。 コンテンツをノード間でコピーするのではなく、ノード間のリンクを変更することにより、順序付けを維持した状態でバケットに要素を挿入します。 つまり、残りの要素に影響を与えずに、要素を自由に挿入および削除できます。

オブジェクトは、型の格納されたデリゲート オブジェクトを呼び出すことによって、制御する各バケットを並べ替えます hash_set::key_compare。 hash_set の構築時に、格納されているデリゲート オブジェクトを指定できます。デリゲート オブジェクトを指定しない場合、既定値は比較 operator<=(key_type, key_type) です。

格納されているデリゲート オブジェクトにアクセスするには、メンバー関数 hash_set::key_compを呼び出します。 このようなデリゲート オブジェクトでは、型 hash_set::key_typeのキー間で同等の順序を定義する必要があります。 つまり、任意の 2 つのキー XY については、次のようになります。

key_comp()(X, Y) は、すべての呼び出しで同じブール値の結果を返します。

key_comp()(X, Y) && key_comp()(Y, X) が true の場合、XY の順序付けが等しくなります。

同じようにoperator<=(key_type, key_type)operator>=(key_type, key_type)動作する、またはoperator==(key_type, key_type)同等の順序を定義する順序付けルール。

コンテナーは、キーの順序が同等の要素 (および同じ整数値に対するハッシュ) がバケット内で隣接していることを確認します。 テンプレート クラス hash_map (STL/CLR) とは異なり、テンプレート クラス hash_multimap のオブジェクトでは、すべての要素のキーが一意である必要はありません。 (2 つ以上のキーの順序付けを等しくすることができます)。

オブジェクトは、格納 hash_set::hasherされている型のデリゲート オブジェクトを呼び出すことによって、特定の順序付けキーを含めるバケットを決定します。 この格納されたオブジェクトにアクセスするには、メンバー関数 hash_set::hash_delegate を呼び出して、キー値に依存する整数値を取得します。 hash_set の構築時に、格納されているデリゲート オブジェクトを指定できます。デリゲート オブジェクトを指定しない場合、既定値は関数 System::Object::hash_value(key_type) です。 つまり、任意のキー XY については、次のようになります。

hash_delegate()(X) は、すべての呼び出しで同じ整数の結果を返します。

XY の順序付けが等しい場合、hash_delegate()(X)hash_delegate()(Y) と同じ整数の結果を返す必要があります。

各要素には、個別のキーとマップされた値が含まれます。 シーケンスは、一定の時間で任意の要素の検索、挿入、および削除を許可する方法で表されます。 つまり、操作の数は、少なくとも最良のケースでは、シーケンス内の要素の数に依存しません。 さらに、要素を挿入すると反復子が無効になり、要素を削除すると、削除された要素を指す反復子のみが無効になります。

ただし、ハッシュ値が均一に分散されていない場合は、ハッシュ テーブルが縮退する可能性があります。 極端な場合 (常に同じ値を返すハッシュ関数の場合)、検索、挿入、および削除は、シーケンス内の要素の数 (線形時間) に比例します。 コンテナーでは、適切なハッシュ関数、平均バケット サイズ、ハッシュ テーブル サイズ (バケットの総数) を選択しようとしますが、これらの選択肢のいずれかまたはすべてをオーバーライドできます。 例えば、関数 hash_set::max_load_factorhash_set::rehash.

A は hash_multimap 双方向反復子をサポートしています。つまり、被制御シーケンス内の要素を指定する反復子を指定すると、隣接する要素にステップ インできます。 特殊なヘッド ノードは、によって end()返される反復子に対応します。 この反復子をデクリメントすると、被制御シーケンス内の最後の要素 (存在する場合) に到達できます。 反復子を hash_multimap インクリメントしてヘッド ノードに到達すると、等しい end()値と比較されます。 ただし、返される end()反復子を逆参照することはできません。

数値の位置を指定して要素を hash_multimap 直接参照することはできません。 これにはランダム アクセス反復子が必要です。

反復子は hash_multimap 、関連付けられた hash_multimap ノードへのハンドルを格納し、関連付けられたコンテナーへのハンドルを格納します。 反復子は、関連付けられているコンテナー オブジェクトでのみ使用できます。 hash_multimap反復子メイン関連付けられたhash_multimapノードが一部hash_multimapに関連付けられている限り有効です。 さらに、有効な反復子は逆参照可能です。 指定した要素値にアクセスしたり変更したりするために使用できます(等しくない end()限り)。

要素を消去または削除すると、格納されている値のデストラクターが呼び出されます。 コンテナーを破棄すると、すべての要素が消去されます。 したがって、要素型が ref クラスのコンテナーでは、コンテナーよりも有効期間が長い要素はありません。 ただし、ハンドルのコンテナーでは、その要素は破棄されません。

メンバー

hash_multimap::begin

被制御シーケンスの先頭を指定します。

構文

iterator begin();

解説

このメンバー関数は、被制御シーケンスの最初の要素 (または空のシーケンスの末尾の次の位置) を指定する双方向反復子を返します。 これを使用して被制御シーケンスの先頭を指定する反復子を current 取得しますが、被制御シーケンスの長さが変わると状態が変わる可能性があります。

// cliext_hash_multimap_begin.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // inspect first two items
    Myhash_multimap::iterator it = c1.begin();
    System::Console::WriteLine("*begin() = [{0} {1}]",
        it->first, it->second);
    ++it;
    System::Console::WriteLine("*++begin() = [{0} {1}]",
        it->first, it->second);
    return (0);
    }
[a 1] [b 2] [c 3]
*begin() = [a 1]
*++begin() = [b 2]

hash_multimap::bucket_count

バケット数をカウントします。

構文

int bucket_count();

解説

このメンバー関数は、現在のバケット数を返します。 ハッシュ テーブルのサイズを確認する場合に、これを使用します。

// cliext_hash_multimap_bucket_count.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1 = gcnew Myhash_multimap;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // inspect current parameters
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    System::Console::WriteLine();

    // change max_load_factor and redisplay
    c1.max_load_factor(0.25f);
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    System::Console::WriteLine();

    // rehash and redisplay
    c1.rehash(100);
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    return (0);
    }
[a 1] [b 2] [c 3]
bucket_count() = 16
load_factor() = 0.1875
max_load_factor() = 4

bucket_count() = 16
load_factor() = 0.1875
max_load_factor() = 0.25

bucket_count() = 128
load_factor() = 0.0234375
max_load_factor() = 0.25

hash_multimap::clear

すべての要素を削除します。

構文

void clear();

解説

メンバー関数は、erase(begin(), end()) を効果的に呼び出します。 被制御シーケンスが空であることを確実にするために使います。

// cliext_hash_multimap_clear.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // clear the container and reinspect
    c1.clear();
    System::Console::WriteLine("size() = {0}", c1.size());

    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));

    // display contents " [a 1] [b 2]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    c1.clear();
    System::Console::WriteLine("size() = {0}", c1.size());
    return (0);
    }
[a 1] [b 2] [c 3]
size() = 0
[a 1] [b 2]
size() = 0

hash_multimap::const_iterator

被制御シーケンスの定数反復子の型です。

構文

typedef T2 const_iterator;

解説

この型は、被制御シーケンスの定数双方向反復子として使用できる未指定の T2 型のオブジェクトを表します。

// cliext_hash_multimap_const_iterator.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    Myhash_multimap::const_iterator cit = c1.begin();
    for (; cit != c1.end(); ++cit)
        System::Console::Write("[{0} {1}] ", cit->first, cit->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]

hash_multimap::const_reference

要素への定数参照の型です。

構文

typedef value_type% const_reference;

解説

この型は、要素への定数参照を表します。

// cliext_hash_multimap_const_reference.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    Myhash_multimap::const_iterator cit = c1.begin();
    for (; cit != c1.end(); ++cit)
        {   // get a const reference to an element
        Myhash_multimap::const_reference cref = *cit;
        System::Console::Write("[{0} {1}] ", cref->first, cref->second);
        }
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]

hash_multimap::const_reverse_iterator

被制御シーケンスの定数反転反復子の型です。

構文

typedef T4 const_reverse_iterator;

解説

この型は、被制御シーケンスの定数反転反復子として使用できる未指定の T4 型のオブジェクトを表します。

// cliext_hash_multimap_const_reverse_iterator.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]" reversed
    Myhash_multimap::const_reverse_iterator crit = c1.rbegin();
    for (; crit != c1.rend(); ++crit)
        System::Console::Write("[{0} {1}] ", crit->first, crit->second);
    System::Console::WriteLine();
    return (0);
    }
[c 3] [b 2] [a 1]

hash_multimap::count

指定したキーに一致する要素の数を検索します。

構文

size_type count(key_type key);

パラメーター

key
検索対象のキー値。

解説

このメンバー関数は、次の値と同等の順序を持つ、制御シーケンス内の要素の数を key返します。 これを使用して、指定したキーと一致する、現在、制御シーケンス内の要素の数を決定します。

// cliext_hash_multimap_count.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    System::Console::WriteLine("count(L'A') = {0}", c1.count(L'A'));
    System::Console::WriteLine("count(L'b') = {0}", c1.count(L'b'));
    System::Console::WriteLine("count(L'C') = {0}", c1.count(L'C'));
    return (0);
    }
[a 1] [b 2] [c 3]
count(L'A') = 0
count(L'b') = 1
count(L'C') = 0

hash_multimap::d ifference_type

2 つの要素間の符号付きの距離を表す型です。

構文

typedef int difference_type;

解説

この型は、場合によっては負の要素数を表します。

// cliext_hash_multimap_difference_type.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // compute positive difference
    Myhash_multimap::difference_type diff = 0;
    for (Myhash_multimap::iterator it = c1.begin(); it != c1.end(); ++it)
        ++diff;
    System::Console::WriteLine("end()-begin() = {0}", diff);

    // compute negative difference
    diff = 0;
    for (Myhash_multimap::iterator it = c1.end(); it != c1.begin(); --it)
        --diff;
    System::Console::WriteLine("begin()-end() = {0}", diff);
    return (0);
    }
[a 1] [b 2] [c 3]
end()-begin() = 3
begin()-end() = -3

hash_multimap::empty

要素が存在しないかどうかをテストします。

構文

bool empty();

解説

このメンバー関数は、被制御シーケンスが空の場合に true を返します。 これは size() == 0 と同じです。 これを使用して、空かどうかを hash_multimap テストします。

// cliext_hash_multimap_empty.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    System::Console::WriteLine("size() = {0}", c1.size());
    System::Console::WriteLine("empty() = {0}", c1.empty());

    // clear the container and reinspect
    c1.clear();
    System::Console::WriteLine("size() = {0}", c1.size());
    System::Console::WriteLine("empty() = {0}", c1.empty());
    return (0);
    }
[a 1] [b 2] [c 3]
size() = 3
empty() = False
size() = 0
empty() = True

hash_multimap::end

被制御シーケンスの末尾を指定します。

構文

iterator end();

解説

このメンバー関数は、被制御シーケンスの末尾を越えたところを示す双方向反復子を返します。 これを使用して、被制御シーケンスの末尾を指定する反復子を取得します。その状態は、制御シーケンスの長さが変更されても変わりません。

// cliext_hash_multimap_end.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // inspect last two items
    Myhash_multimap::iterator it = c1.end();
    --it;
    --it;
    System::Console::WriteLine("*-- --end() = [{0} {1}]",
        it->first, it->second);
    ++it;
    System::Console::WriteLine("*--end() = [{0} {1}]",
        it->first, it->second);
    return (0);
    }
[a 1] [b 2] [c 3]
*-- --end() = [b 2]
*--end() = [c 3]

hash_multimap::equal_range

指定したキーに一致する範囲を検索します。

構文

cliext::pair<iterator, iterator> equal_range(key_type key);

パラメーター

key
検索対象のキー値。

解説

このメンバー関数は、反復子 cliext::pair<iterator, iterator>(lower_bound(key), upper_bound(key)) のペアを返します。 指定したキーに一致する、被制御シーケンス内の現在の要素の範囲を特定するために使います。

// cliext_hash_multimap_equal_range.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
typedef Myhash_multimap::pair_iter_iter Pairii;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // display results of failed search
    Pairii pair1 = c1.equal_range(L'x');
    System::Console::WriteLine("equal_range(L'x') empty = {0}",
        pair1.first == pair1.second);

    // display results of successful search
    pair1 = c1.equal_range(L'b');
    for (; pair1.first != pair1.second; ++pair1.first)
        System::Console::Write("[{0} {1}] ",
            pair1.first->first, pair1.first->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]
equal_range(L'x') empty = True
[b 2]

hash_multimap::erase

指定した位置にある要素を削除します。

構文

iterator erase(iterator where);
iterator erase(iterator first, iterator last);
bool erase(key_type key)

パラメーター

first
消去する範囲の先頭。

key
消去するキー値。

last
消去する範囲の末尾。

where
消去する要素。

解説

最初のメンバー関数は、指定された被制御シーケンスの要素を削除し、削除されたwhere要素を超えて、またはend()そのような要素が存在しない場合にメイン最初の要素を指定する反復子を返します。 1 つの要素を削除する場合に使います。

2 番目のメンバー関数は、半開[first, last)範囲の被制御シーケンスの要素を削除し、削除された要素を超えて、またはend()そのような要素が存在しない場合メイン最初の要素を指定する反復子を返します。 0 個以上の連続する要素を削除する場合に、これを使用します。

3 番目のメンバー関数は、キーの順序 keyが同等の制御シーケンスの要素を削除し、削除された要素の数を返します。 指定したキーに一致するすべての要素を削除してカウントする場合に、これを使用します。

各要素の消去には、被制御シーケンス内の要素数の対数に比例した時間が必要です。

// cliext_hash_multimap_erase.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    cliext::hash_multimap<wchar_t, int> c1;
    c1.insert(cliext::hash_multimap<wchar_t, int>::make_value(L'a', 1));
    c1.insert(cliext::hash_multimap<wchar_t, int>::make_value(L'b', 2));
    c1.insert(cliext::hash_multimap<wchar_t, int>::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (cliext::hash_multimap<wchar_t, int>::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // erase an element and reinspect
    cliext::hash_multimap<wchar_t, int>::iterator it =
        c1.erase(c1.begin());
    System::Console::WriteLine("erase(begin()) = [{0} {1}]",
        it->first, it->second);

    // add elements and display " b c d e"
    c1.insert(cliext::hash_multimap<wchar_t, int>::make_value(L'd', 4));
    c1.insert(cliext::hash_multimap<wchar_t, int>::make_value(L'e', 5));
    for each (cliext::hash_multimap<wchar_t, int>::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // erase all but end
    it = c1.end();
    it = c1.erase(c1.begin(), --it);
    System::Console::WriteLine("erase(begin(), end()-1) = [{0} {1}]",
        it->first, it->second);
    System::Console::WriteLine("size() = {0}", c1.size());

    // erase end
    System::Console::WriteLine("erase(L'x') = {0}", c1.erase(L'x'));
    System::Console::WriteLine("erase(L'e') = {0}", c1.erase(L'e'));
    return (0);
    }
[a 1] [b 2] [c 3]
erase(begin()) = [b 2]
[b 2] [c 3] [d 4] [e 5]
erase(begin(), end()-1) = [e 5]
size() = 1
erase(L'x') = 0
erase(L'e') = 1

hash_multimap::find

指定したキーに一致する要素を検索します。

構文

iterator find(key_type key);

パラメーター

key
検索対象のキー値。

解説

被制御シーケンス内の少なくとも 1 つの要素の順序 keyが等しい場合、メンバー関数は、これらの要素のいずれかを指定する反復子を返します。それ以外の場合は返します hash_multimap::end()。 被制御シーケンス内の指定したキーに一致する現在の要素を検索する場合に使います。

// cliext_hash_multimap_find.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    System::Console::WriteLine("find {0} = {1}",
        L'A', c1.find(L'A') != c1.end());

    Myhash_multimap::iterator it = c1.find(L'b');
    System::Console::WriteLine("find {0} = [{1} {2}]",
        L'b', it->first, it->second);

    System::Console::WriteLine("find {0} = {1}",
        L'C', c1.find(L'C') != c1.end());
    return (0);
    }
[a 1] [b 2] [c 3]
find A = False
find b = [b 2]
find C = False

hash_multimap::generic_container

コンテナーのジェネリック インターフェイスの型です。

構文

typedef Microsoft::VisualC::StlClr::
    IHash<GKey, GValue>
    generic_container;

解説

この型は、このテンプレート コンテナー クラスのジェネリック インターフェイスを表します。

// cliext_hash_multimap_generic_container.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct a generic container
    Myhash_multimap::generic_container^ gc1 = %c1;
    for each (Myhash_multimap::value_type elem in gc1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // modify generic and display original
    gc1->insert(Myhash_multimap::make_value(L'd', 4));
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // modify original and display generic
    c1.insert(Myhash_multimap::make_value(L'e', 5));
    for each (Myhash_multimap::value_type elem in gc1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3] [d 4]
[a 1] [b 2] [c 3] [d 4] [e 5]

hash_multimap::generic_iterator

コンテナーのジェネリック インターフェイスで使用する反復子の型です。

構文

typedef Microsoft::VisualC::StlClr::Generic::
    ContainerBidirectionalIterator<generic_value>
    generic_iterator;

解説

この型は、このテンプレート コンテナー クラスのジェネリック インターフェイスで使用できるジェネリック反復子を表します。

// cliext_hash_multimap_generic_iterator.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct a generic container
    Myhash_multimap::generic_container^ gc1 = %c1;
    for each (Myhash_multimap::value_type elem in gc1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // get an element and display it
    Myhash_multimap::generic_iterator gcit = gc1->begin();
    Myhash_multimap::generic_value gcval = *gcit;
    System::Console::Write("[{0} {1}] ", gcval->first, gcval->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3]
[a 1]

hash_multimap::generic_reverse_iterator

コンテナーのジェネリック インターフェイスで使用する反転反復子の型です。

構文

typedef Microsoft::VisualC::StlClr::Generic::
    ReverseRandomAccessIterator<generic_value>
    generic_reverse_iterator;

解説

この型は、このテンプレート コンテナー クラスのジェネリック インターフェイスで使用できるジェネリック反転反復子を表します。

// cliext_hash_multimap_generic_reverse_iterator.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct a generic container
    Myhash_multimap::generic_container^ gc1 = %c1;
    for each (Myhash_multimap::value_type elem in gc1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // get an element and display it
    Myhash_multimap::generic_reverse_iterator gcit = gc1->rbegin();
    Myhash_multimap::generic_value gcval = *gcit;
    System::Console::WriteLine("[{0} {1}] ", gcval->first, gcval->second);
    return (0);
    }
[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3]
[c 3]

hash_multimap::generic_value

コンテナーのジェネリック インターフェイスで使用する要素の型です。

構文

typedef GValue generic_value;

解説

この型は、このテンプレート コンテナー クラスのジェネリック インターフェイスで使用する、格納されている要素の値を記述する GValue 型のオブジェクトを表します。

// cliext_hash_multimap_generic_value.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct a generic container
    Myhash_multimap::generic_container^ gc1 = %c1;
    for each (Myhash_multimap::value_type elem in gc1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // get an element and display it
    Myhash_multimap::generic_iterator gcit = gc1->begin();
    Myhash_multimap::generic_value gcval = *gcit;
    System::Console::WriteLine("[{0} {1}] ", gcval->first, gcval->second);
    return (0);
    }
[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3]
[a 1]

hash_multimap::hash_delegate

指定したキーに一致する要素を検索します。

構文

hasher^ hash_delegate();

解説

このメンバー関数は、キー値を整数に変換するために使用されるデリゲートを返します。 キーをハッシュする場合に、これを使用します。

// cliext_hash_multimap_hash_delegate.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    Myhash_multimap::hasher^ myhash = c1.hash_delegate();

    System::Console::WriteLine("hash(L'a') = {0}", myhash(L'a'));
    System::Console::WriteLine("hash(L'b') = {0}", myhash(L'b'));
    return (0);
    }
hash(L'a') = 1616896120
hash(L'b') = 570892832

hash_multimap::hash_multimap

コンテナー オブジェクトを構築します。

構文

hash_multimap();
explicit hash_multimap(key_compare^ pred);
hash_multimap(key_compare^ pred, hasher^ hashfn);
hash_multimap(hash_multimap<Key, Mapped>% right);
hash_multimap(hash_multimap<Key, Mapped>^ right);
template<typename InIter>
    hash_multimaphash_multimap(InIter first, InIter last);
template<typename InIter>
    hash_multimap(InIter first, InIter last,
        key_compare^ pred);
template<typename InIter>
    hash_multimap(InIter first, InIter last,
        key_compare^ pred, hasher^ hashfn);
hash_multimap(System::Collections::Generic::IEnumerable<GValue>^ right);
hash_multimap(System::Collections::Generic::IEnumerable<GValue>^ right,
    key_compare^ pred);
hash_multimap(System::Collections::Generic::IEnumerable<GValue>^ right,
    key_compare^ pred, hasher^ hashfn);

パラメーター

first
挿入する範囲の先頭。

hashfn
キーをバケットにマップするハッシュ関数。

last
挿入する範囲の末尾。

pred
被制御シーケンスの順序付けの述語。

right
挿入するオブジェクトまたは範囲。

解説

コンストラクター:

hash_multimap();

既定の順序付けの述語 key_compare() および既定のハッシュ関数を使用して、要素のない被制御シーケンスを初期化します。 既定の順序付けの述語とハッシュ関数を使用して、空である最初の被制御シーケンスを指定する場合に、これを使用します。

コンストラクター:

explicit hash_multimap(key_compare^ pred);

は、要素なしで、順序付け述語 predを使用して、および既定のハッシュ関数を使用して、制御シーケンスを初期化します。 指定した順序付けの述語と既定のハッシュ関数を使用して、空である最初の被制御シーケンスを指定する場合に、これを使用します。

コンストラクター:

hash_multimap(key_compare^ pred, hasher^ hashfn);

は、要素なしで、順序述語 predを使用して、およびハッシュ関数 hashfnを使用して、制御シーケンスを初期化します。 指定した順序付けの述語とハッシュ関数を使用して、空である最初の被制御シーケンスを指定する場合に、これを使用します。

コンストラクター:

hash_multimap(hash_multimap<Key, Mapped>% right);

既定の順序付けの述語と既定のハッシュ関数を使用して、シーケンス [right.begin(), right.end()) で被制御シーケンスを初期化します。 これを使用して、既定の順序付け述語とハッシュ関数を使用して、オブジェクトrightによってhash_multimap制御されるシーケンスのコピーである初期被制御シーケンスを指定します。

コンストラクター:

hash_multimap(hash_multimap<Key, Mapped>^ right);

既定の順序付けの述語と既定のハッシュ関数を使用して、シーケンス [right->begin(), right->end()) で被制御シーケンスを初期化します。 これを使用して、既定の順序付け述語とハッシュ関数を使用して、オブジェクトrightによってhash_multimap制御されるシーケンスのコピーである初期被制御シーケンスを指定します。

コンストラクター:

template<typename InIter> hash_multimap(InIter first, InIter last);

は、シーケンス、既定の [first, last)順序付け述語、および既定のハッシュ関数を使用して、制御シーケンスを初期化します。 既定の順序付けの述語とハッシュ関数を使用して、被制御シーケンスを別のシーケンスのコピーにする場合に、これを使用します。

コンストラクター:

template<typename InIter> hash_multimap(InIter first, InIter last, key_compare^ pred);

は、シーケンス [first, last)、順序述語 pred、および既定のハッシュ関数を使用して、制御シーケンスを初期化します。 指定した順序付けの述語と既定のハッシュ関数を使用して、被制御シーケンスを別のシーケンスのコピーにする場合に、これを使用します。

コンストラクター:

template<typename InIter> hash_multimap(InIter first, InIter last, key_compare^ pred, hasher^ hashfn);

は、シーケンス [first, last)、順序述語 pred、およびハッシュ関数 hashfnを使用して、制御シーケンスを初期化します。 指定した順序付けの述語とハッシュ関数を使用して、被制御シーケンスを別のシーケンスのコピーにする場合に、これを使用します。

コンストラクター:

hash_multimap(System::Collections::Generic::IEnumerable<Key>^ right);

は、列挙子 rightによって指定されたシーケンス、既定の順序付け述語、および既定のハッシュ関数を使用して、制御シーケンスを初期化します。 既定の順序付けの述語とハッシュ関数を使用して、被制御シーケンスを列挙子によって記述された別のシーケンスのコピーにする場合に、これを使用します。

コンストラクター:

hash_multimap(System::Collections::Generic::IEnumerable<Key>^ right, key_compare^ pred);

は、列挙子 rightによって指定されたシーケンス、順序付け述語 pred、および既定のハッシュ関数を使用して、制御シーケンスを初期化します。 指定した順序付けの述語と既定のハッシュ関数を使用して、被制御シーケンスを列挙子によって記述された別のシーケンスのコピーにする場合に、これを使用します。

コンストラクター:

hash_multimap(System::Collections::Generic::IEnumerable<Key>^ right, key_compare^ pred, hasher^ hashfn);

は、列挙子 rightによって指定されたシーケンス、順序付け述語 pred、およびハッシュ関数 hashfnを使用して、制御シーケンスを初期化します。 指定した順序付けの述語とハッシュ関数を使用して、被制御シーケンスを列挙子によって記述された別のシーケンスのコピーにする場合に、これを使用します。

// cliext_hash_multimap_construct.cpp
// compile with: /clr
#include <cliext/hash_map>

int myfun(wchar_t key)
    { // hash a key
    return (key ^ 0xdeadbeef);
    }

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
// construct an empty container
    Myhash_multimap c1;
    System::Console::WriteLine("size() = {0}", c1.size());

    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct with an ordering rule
    Myhash_multimap c2 = cliext::greater_equal<wchar_t>();
    System::Console::WriteLine("size() = {0}", c2.size());

    c2.insert(c1.begin(), c1.end());
    for each (Myhash_multimap::value_type elem in c2)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct with an ordering rule and hash function
    Myhash_multimap c2h(cliext::greater_equal<wchar_t>(),
        gcnew Myhash_multimap::hasher(&myfun));
    System::Console::WriteLine("size() = {0}", c2h.size());

    c2h.insert(c1.begin(), c1.end());
    for each (Myhash_multimap::value_type elem in c2h)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    System::Console::WriteLine();

    // construct with an iterator range
    Myhash_multimap c3(c1.begin(), c1.end());
    for each (Myhash_multimap::value_type elem in c3)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct with an iterator range and an ordering rule
    Myhash_multimap c4(c1.begin(), c1.end(),
        cliext::greater_equal<wchar_t>());
    for each (Myhash_multimap::value_type elem in c4)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct with an iterator range and an ordering rule and hash function
    Myhash_multimap c4h(c1.begin(), c1.end(),
        cliext::greater_equal<wchar_t>(),
        gcnew Myhash_multimap::hasher(&myfun));
    for each (Myhash_multimap::value_type elem in c4h)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    System::Console::WriteLine();

    // construct with an enumeration
    Myhash_multimap c5(   // NOTE: cast is not needed
        (System::Collections::Generic::IEnumerable<
            Myhash_multimap::value_type>^)%c3);
    for each (Myhash_multimap::value_type elem in c5)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct with an enumeration and an ordering rule
    Myhash_multimap c6(   // NOTE: cast is not needed
        (System::Collections::Generic::IEnumerable<
            Myhash_multimap::value_type>^)%c3,
                cliext::greater_equal<wchar_t>());
    for each (Myhash_multimap::value_type elem in c6)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct with an enumeration and an ordering rule and hash function
    Myhash_multimap c6h(   // NOTE: cast is not needed
        (System::Collections::Generic::IEnumerable<
            Myhash_multimap::value_type>^)%c3,
                cliext::greater_equal<wchar_t>(),
                gcnew Myhash_multimap::hasher(&myfun));
    for each (Myhash_multimap::value_type elem in c6h)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    System::Console::WriteLine();

    // construct by copying another container
    Myhash_multimap c7(c4);
    for each (Myhash_multimap::value_type elem in c7)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct by copying a container handle
    Myhash_multimap c8(%c3);
    for each (Myhash_multimap::value_type elem in c8)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    return (0);
    }
size() = 0
[a 1] [b 2] [c 3]
size() = 0
[a 1] [b 2] [c 3]
size() = 0
[c 3] [b 2] [a 1]

[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3]
[c 3] [b 2] [a 1]

[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3]
[c 3] [b 2] [a 1]

[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3]

hash_multimap::hasher

キーのハッシュ デリゲートです。

構文

Microsoft::VisualC::StlClr::UnaryDelegate<GKey, int>
    hasher;

解説

この型は、キー値を整数に変換するデリゲートを表します。

// cliext_hash_multimap_hasher.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    Myhash_multimap::hasher^ myhash = c1.hash_delegate();

    System::Console::WriteLine("hash(L'a') = {0}", myhash(L'a'));
    System::Console::WriteLine("hash(L'b') = {0}", myhash(L'b'));
    return (0);
    }
hash(L'a') = 1616896120
hash(L'b') = 570892832

hash_multimap::insert

要素を追加します。

構文

iterator insert(value_type val);
iterator insert(iterator where, value_type val);
template<typename InIter>
    void insert(InIter first, InIter last);
void insert(System::Collections::Generic::IEnumerable<value_type>^ right);

パラメーター

first
挿入する範囲の先頭。

last
挿入する範囲の末尾。

right
挿入する列挙型。

val
挿入するキー値。

where
コンテナー内の挿入位置 (ヒントのみ)。

解説

各メンバー関数は、残りのオペランドによって指定されたシーケンスを挿入します。

最初のメンバー関数は、値 valを持つ要素を挿入し、新しく挿入された要素を指定する反復子を返します。 1 つの要素を挿入する場合に、これを使用します。

2 番目のメンバー関数は、(パフォーマンスを向上させるために) ヒントとして使用して、値 valを持 where つ要素を挿入し、新しく挿入された要素を指定する反復子を返します。 これを使用して、知っている要素の横にある可能性のある 1 つの要素を挿入します。

3 番目のメンバー関数は、シーケンスを挿入します [first, last)。 別のシーケンスからコピーした 0 個以上の要素を挿入する場合に、これを使用します。

4 番目のメンバー関数は、によって指定されたシーケンスを挿入します。right 列挙子によって記述されたシーケンスを挿入する場合に、これを使用します。

各要素の挿入には、被制御シーケンス内の要素数の対数に比例した時間が必要です。 ただし、挿入ポイントの横にある要素を指定するヒントを指定すると、挿入は償却定数時間で発生する可能性があります。

// cliext_hash_multimap_insert.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // insert a single value, unique and duplicate
    Myhash_multimap::iterator it =
        c1.insert(Myhash_multimap::make_value(L'x', 24));
    System::Console::WriteLine("insert([L'x' 24]) = [{0} {1}]",
        it->first, it->second);

    it = c1.insert(Myhash_multimap::make_value(L'b', 2));
    System::Console::WriteLine("insert([L'b' 2]) = [{0} {1}]",
        it->first, it->second);

    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // insert a single value with hint
    it = c1.insert(c1.begin(), Myhash_multimap::make_value(L'y', 25));
    System::Console::WriteLine("insert(begin(), [L'y' 25]) = [{0} {1}]",
        it->first, it->second);
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // insert an iterator range
    Myhash_multimap c2;
    it = c1.end();
    c2.insert(c1.begin(), --it);
    for each (Myhash_multimap::value_type elem in c2)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // insert an enumeration
    Myhash_multimap c3;
    c3.insert(   // NOTE: cast is not needed
        (System::Collections::Generic::
            IEnumerable<Myhash_multimap::value_type>^)%c1);
    for each (Myhash_multimap::value_type elem in c3)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]
insert([L'x' 24]) = [x 24]
insert([L'b' 2]) = [b 2]
[a 1] [b 2] [b 2] [c 3] [x 24]
insert(begin(), [L'y' 25]) = [y 25]
[a 1] [b 2] [b 2] [c 3] [x 24] [y 25]
[a 1] [b 2] [b 2] [c 3] [x 24]
[a 1] [b 2] [b 2] [c 3] [x 24] [y 25]

hash_multimap::iterator

被制御シーケンスの反復子の型です。

構文

typedef T1 iterator;

解説

この型は、被制御シーケンスの双方向反復子として使用できる未指定の T1 型のオブジェクトを表します。

// cliext_hash_multimap_iterator.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    Myhash_multimap::iterator it = c1.begin();
    for (; it != c1.end(); ++it)
        System::Console::Write("[{0} {1}] ", it->first, it->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]

hash_multimap::key_comp

2 つのキーの順序付けデリゲートをコピーします。

構文

key_compare^key_comp();

解説

このメンバー関数は、被制御シーケンスの順序付けに使用される順序付けデリゲートを返します。 これを使用して、2 つのキーを比較します。

// cliext_hash_multimap_key_comp.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    Myhash_multimap::key_compare^ kcomp = c1.key_comp();

    System::Console::WriteLine("compare(L'a', L'a') = {0}",
        kcomp(L'a', L'a'));
    System::Console::WriteLine("compare(L'a', L'b') = {0}",
        kcomp(L'a', L'b'));
    System::Console::WriteLine("compare(L'b', L'a') = {0}",
        kcomp(L'b', L'a'));
    System::Console::WriteLine();

    // test a different ordering rule
    Myhash_multimap c2 = cliext::greater<wchar_t>();
    kcomp = c2.key_comp();

    System::Console::WriteLine("compare(L'a', L'a') = {0}",
        kcomp(L'a', L'a'));
    System::Console::WriteLine("compare(L'a', L'b') = {0}",
        kcomp(L'a', L'b'));
    System::Console::WriteLine("compare(L'b', L'a') = {0}",
        kcomp(L'b', L'a'));
    return (0);
    }
compare(L'a', L'a') = True
compare(L'a', L'b') = True
compare(L'b', L'a') = False

compare(L'a', L'a') = False
compare(L'a', L'b') = False
compare(L'b', L'a') = True

hash_multimap::key_compare

2 つのキーの順序付けデリゲートです。

構文

Microsoft::VisualC::StlClr::BinaryDelegate<GKey, GKey, bool>
    key_compare;

解説

この型は、キー引数の順序付けを決定するデリゲートのシノニムです。

// cliext_hash_multimap_key_compare.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    Myhash_multimap::key_compare^ kcomp = c1.key_comp();

    System::Console::WriteLine("compare(L'a', L'a') = {0}",
        kcomp(L'a', L'a'));
    System::Console::WriteLine("compare(L'a', L'b') = {0}",
        kcomp(L'a', L'b'));
    System::Console::WriteLine("compare(L'b', L'a') = {0}",
        kcomp(L'b', L'a'));
    System::Console::WriteLine();

    // test a different ordering rule
    Myhash_multimap c2 = cliext::greater<wchar_t>();
    kcomp = c2.key_comp();

    System::Console::WriteLine("compare(L'a', L'a') = {0}",
        kcomp(L'a', L'a'));
    System::Console::WriteLine("compare(L'a', L'b') = {0}",
        kcomp(L'a', L'b'));
    System::Console::WriteLine("compare(L'b', L'a') = {0}",
        kcomp(L'b', L'a'));
    return (0);
    }
compare(L'a', L'a') = True
compare(L'a', L'b') = True
compare(L'b', L'a') = False

compare(L'a', L'a') = False
compare(L'a', L'b') = False
compare(L'b', L'a') = True

hash_multimap::key_type

順序付けキーの型です。

構文

typedef Key key_type;

解説

この型は、テンプレート パラメーター Keyのシノニムです。

// cliext_hash_multimap_key_type.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]" using key_type
    for (Myhash_multimap::iterator it = c1.begin(); it != c1.end(); ++it)
        {   // store element in key_type object
        Myhash_multimap::key_type val = it->first;

        System::Console::Write("{0} ", val);
        }
    System::Console::WriteLine();
    return (0);
    }
a b c

hash_multimap::load_factor

バケットごとの平均要素数をカウントします。

構文

float load_factor();

解説

このメンバー関数は、(float)size() / bucket_count() を返します。 バケットの平均サイズを決定するために使います。

// cliext_hash_multimap_load_factor.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1 = gcnew Myhash_multimap;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // inspect current parameters
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    System::Console::WriteLine();

    // change max_load_factor and redisplay
    c1.max_load_factor(0.25f);
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    System::Console::WriteLine();

    // rehash and redisplay
    c1.rehash(100);
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    return (0);
    }
[a 1] [b 2] [c 3]
bucket_count() = 16
load_factor() = 0.1875
max_load_factor() = 4

bucket_count() = 16
load_factor() = 0.1875
max_load_factor() = 0.25

bucket_count() = 128
load_factor() = 0.0234375
max_load_factor() = 0.25

hash_multimap::lower_bound

指定したキーに一致する範囲の先頭を検索します。

構文

iterator lower_bound(key_type key);

パラメーター

key
検索対象のキー値。

解説

メンバー関数は、同じバケットkeyにハッシュし、同等の順序を持つ、制御シーケンス内の最初の要素Xkey決定します。 そのような要素が存在しない場合は返 hash_multimap::end()されます。それ以外の場合は、指定する反復子を返します X。 指定したキーに一致する、被制御シーケンス内の現在の要素のシーケンスの先頭を検索する場合に使います。

// cliext_hash_multimap_lower_bound.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    System::Console::WriteLine("lower_bound(L'x')==end() = {0}",
        c1.lower_bound(L'x') == c1.end());

    Myhash_multimap::iterator it = c1.lower_bound(L'a');
    System::Console::WriteLine("*lower_bound(L'a') = [{0} {1}]",
        it->first, it->second);
    it = c1.lower_bound(L'b');
    System::Console::WriteLine("*lower_bound(L'b') = [{0} {1}]",
        it->first, it->second);
    return (0);
    }
[a 1] [b 2] [c 3]
lower_bound(L'x')==end() = True
*lower_bound(L'a') = [a 1]
*lower_bound(L'b') = [b 2]

hash_multimap::make_value

値オブジェクトを構築します。

構文

static value_type make_value(key_type key, mapped_type mapped);

パラメーター

key
使用するキー値。

mapped
検索するマップされた値。

解説

このメンバー関数は、キーが value_type /& で key 、マップされた値 mappedが . 他のいくつかのメンバー関数での使用に適したオブジェクトを作成する場合に使います。

// cliext_hash_multimap_make_value.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]

hash_multimap::mapped_type

各キーに関連付けられた、マップされた値の型です。

構文

typedef Mapped mapped_type;

解説

この型は、テンプレート パラメーター Mappedのシノニムです。

// cliext_hash_multimap_mapped_type.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]" using mapped_type
    for (Myhash_multimap::iterator it = c1.begin(); it != c1.end(); ++it)
        {   // store element in mapped_type object
        Myhash_multimap::mapped_type val = it->second;

        System::Console::Write("{0} ", val);
        }
    System::Console::WriteLine();
    return (0);
    }
1 2 3

hash_multimap::max_load_factor

バケットあたりの最大要素数を取得または設定します。

構文

float max_load_factor();
void max_load_factor(float new_factor);

パラメーター

new_factor
格納する新しい最大テーブル占有率。

解説

最初のメンバー関数は、現在格納されている最大テーブル占有率を返します。 最大バケット サイズを確認する場合に、これを使用します。

2 番目のメンバー関数は、ストアの最大読み込み係数 new_factorを . 後続の挿入まで、自動再ハッシュは行われません。

// cliext_hash_multimap_max_load_factor.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1 = gcnew Myhash_multimap;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // inspect current parameters
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    System::Console::WriteLine();

    // change max_load_factor and redisplay
    c1.max_load_factor(0.25f);
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    System::Console::WriteLine();

    // rehash and redisplay
    c1.rehash(100);
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    return (0);
    }
[a 1] [b 2] [c 3]
bucket_count() = 16
load_factor() = 0.1875
max_load_factor() = 4

bucket_count() = 16
load_factor() = 0.1875
max_load_factor() = 0.25

bucket_count() = 128
load_factor() = 0.0234375
max_load_factor() = 0.25

hash_multimap::operator=

被制御シーケンスを置き換えます。

構文

hash_multimap<Key, Mapped>% operator=(hash_multimap<Key, Mapped>% right);

パラメーター

right
コピーするコンテナー。

解説

メンバー演算子は、オブジェクトにコピー right し、次に返します *this。 これを使用して、被制御シーケンスを right の被制御シーケンスのコピーと置き換えます。

// cliext_hash_multimap_operator_as.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // assign to a new container
    Myhash_multimap c2;
    c2 = c1;
// display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c2)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3]

hash_multimap::rbegin

反転被制御シーケンスの先頭を指定します。

構文

reverse_iterator rbegin();

解説

このメンバー関数は、被制御シーケンスの最後の要素 (または空のシーケンスの先頭の次の位置) を指定する反転反復子を返します。 したがって、逆シーケンスを beginning 指定します。 これを使用して、被制御シーケンスの先頭を current 逆の順序で指定する反復子を取得しますが、被制御シーケンスの長さが変わると状態が変わる可能性があります。

// cliext_hash_multimap_rbegin.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // inspect first two items in reversed sequence
    Myhash_multimap::reverse_iterator rit = c1.rbegin();
    System::Console::WriteLine("*rbegin() = [{0} {1}]",
        rit->first, rit->second);
    ++rit;
    System::Console::WriteLine("*++rbegin() = [{0} {1}]",
        rit->first, rit->second);
    return (0);
    }
[a 1] [b 2] [c 3]
*rbegin() = [c 3]
*++rbegin() = [b 2]

hash_multimap::reference

要素への参照の型です。

構文

typedef value_type% reference;

解説

この型は、要素への参照を表します。

// cliext_hash_multimap_reference.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    Myhash_multimap::iterator it = c1.begin();
    for (; it != c1.end(); ++it)
        {   // get a reference to an element
        Myhash_multimap::reference ref = *it;
        System::Console::Write("[{0} {1}] ", ref->first, ref->second);
        }
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]

hash_multimap::rehash

ハッシュ テーブルをリビルドします。

構文

void rehash();

解説

メンバー関数はハッシュ テーブルを再構築し、次の点 load_factor() <= max_load_factor()を確認します。 それ以外の場合、ハッシュ テーブルのサイズは、挿入後に必要な場合にのみ増加します (サイズが自動的に減少することはありません。これを使用して、ハッシュ テーブルのサイズを調整します。

// cliext_hash_multimap_rehash.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1 = gcnew Myhash_multimap;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // inspect current parameters
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    System::Console::WriteLine();

    // change max_load_factor and redisplay
    c1.max_load_factor(0.25f);
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    System::Console::WriteLine();

    // rehash and redisplay
    c1.rehash(100);
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    return (0);
    }
[a 1] [b 2] [c 3]
bucket_count() = 16
load_factor() = 0.1875
max_load_factor() = 4

bucket_count() = 16
load_factor() = 0.1875
max_load_factor() = 0.25

bucket_count() = 128
load_factor() = 0.0234375
max_load_factor() = 0.25

hash_multimap::rend

反転被制御シーケンスの末尾を指定します。

構文

reverse_iterator rend();

解説

このメンバー関数は、被制御シーケンスの先頭を超えた位置を示す反転反復子を返します。 したがって、逆シーケンスを end 指定します。 これを使用して、被制御シーケンスの末尾を逆の順序で指定 current する反復子を取得しますが、被制御シーケンスの長さが変わると状態が変わる可能性があります。

// cliext_hash_multimap_rend.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // inspect first two items in reversed sequence
    Myhash_multimap::reverse_iterator rit = c1.rend();
    --rit;
    --rit;
    System::Console::WriteLine("*-- --rend() = [{0} {1}]",
        rit->first, rit->second);
    ++rit;
    System::Console::WriteLine("*--rend() = [{0} {1}]",
        rit->first, rit->second);
    return (0);
    }
[a 1] [b 2] [c 3]
*-- --rend() = [b 2]
*--rend() = [a 1]

hash_multimap::reverse_iterator

被制御シーケンスの反転反復子の型です。

構文

typedef T3 reverse_iterator;

解説

この型は、被制御シーケンスの反転反復子として使用できる未指定の T3 型のオブジェクトを表します。

// cliext_hash_multimap_reverse_iterator.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]" reversed
    Myhash_multimap::reverse_iterator rit = c1.rbegin();
    for (; rit != c1.rend(); ++rit)
        System::Console::Write("[{0} {1}] ", rit->first, rit->second);
    System::Console::WriteLine();
    return (0);
    }
[c 3] [b 2] [a 1]

hash_multimap::size

要素の数をカウントします。

構文

size_type size();

解説

このメンバー関数は、被制御シーケンスの長さを返します。 被制御シーケンス内の現在の要素の数を特定する場合に使います。 シーケンスに 0 以外のサイズがあるかどうかを考慮する必要がある場合は、次を参照してください hash_multimap::empty()

// cliext_hash_multimap_size.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // clear the container and reinspect
    c1.clear();
    System::Console::WriteLine("size() = {0} after clearing", c1.size());

    // add elements and clear again
    c1.insert(Myhash_multimap::make_value(L'd', 4));
    c1.insert(Myhash_multimap::make_value(L'e', 5));
    System::Console::WriteLine("size() = {0} after adding 2", c1.size());
    return (0);
    }
[a 1] [b 2] [c 3]
size() = 0 after clearing
size() = 2 after adding 2

hash_multimap::size_type

2 つの要素間の距離を表す、符号付きの型です。

構文

typedef int size_type;

解説

この型は、負でない要素数を表します。

// cliext_hash_multimap_size_type.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // compute positive difference
    Myhash_multimap::size_type diff = 0;
    for (Myhash_multimap::iterator it = c1.begin(); it != c1.end(); ++it)
        ++diff;
    System::Console::WriteLine("end()-begin() = {0}", diff);
    return (0);
    }
[a 1] [b 2] [c 3]
end()-begin() = 3

hash_multimap::swap

2 つのコンテナーのコンテンツを交換します。

構文

void swap(hash_multimap<Key, Mapped>% right);

パラメーター

right
コンテンツを交換するコンテナー。

解説

このメンバー関数は、thisright の間で被制御シーケンスを交換します。 一定時間に実行し、例外をスローしません。 2 つのコンテナーのコンテンツを簡単に交換する方法として、これを使用します。

// cliext_hash_multimap_swap.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct another container with repetition of values
    Myhash_multimap c2;
    c2.insert(Myhash_multimap::make_value(L'd', 4));
    c2.insert(Myhash_multimap::make_value(L'e', 5));
    c2.insert(Myhash_multimap::make_value(L'f', 6));
    for each (Myhash_multimap::value_type elem in c2)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // swap and redisplay
    c1.swap(c2);
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    for each (Myhash_multimap::value_type elem in c2)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]
[d 4] [e 5] [f 6]
[d 4] [e 5] [f 6]
[a 1] [b 2] [c 3]

hash_multimap::to_array

被制御シーケンスを新しい配列にコピーします。

構文

cli::array<value_type>^ to_array();

解説

このメンバー関数は、被制御シーケンスを含む配列を返します。 配列形式の被制御シーケンスのコピーを取得する場合に、これを使用します。

// cliext_hash_multimap_to_array.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // copy the container and modify it
    cli::array<Myhash_multimap::value_type>^ a1 = c1.to_array();

    c1.insert(Myhash_multimap::make_value(L'd', 4));
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // display the earlier array copy
    for each (Myhash_multimap::value_type elem in a1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3] [d 4]
[a 1] [b 2] [c 3]

hash_multimap::upper_bound

指定したキーに一致する範囲の末尾を検索します。

構文

iterator upper_bound(key_type key);

パラメーター

key
検索対象のキー値。

解説

メンバー関数は、同じバケットkeyにハッシュし、同等の順序を持つ、制御シーケンス内の最後の要素Xkey決定します。 このような要素が存在しない場合、または被制御シーケンスの最後の要素である場合 X は返されます。それ以外の場合は、 hash_multimap::end()最初の要素を指定 Xする反復子を返します。 指定したキーに一致する、被制御シーケンス内の現在の要素のシーケンスの末尾を検索する場合に使います。

// cliext_hash_multimap_upper_bound.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_multimap::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    System::Console::WriteLine("upper_bound(L'x')==end() = {0}",
        c1.upper_bound(L'x') == c1.end());

    Myhash_multimap::iterator it = c1.upper_bound(L'a');
    System::Console::WriteLine("*upper_bound(L'a') = [{0} {1}]",
        it->first, it->second);
    it = c1.upper_bound(L'b');
    System::Console::WriteLine("*upper_bound(L'b') = [{0} {1}]",
        it->first, it->second);
    return (0);
    }
[a 1] [b 2] [c 3]
upper_bound(L'x')==end() = True
*upper_bound(L'a') = [b 2]
*upper_bound(L'b') = [c 3]

hash_multimap::value_comp

2 つの要素値の順序付けデリゲートをコピーします。

構文

value_compare^ value_comp();

解説

このメンバー関数は、被制御シーケンスの順序付けに使用される順序付けデリゲートを返します。 2 つの要素値を比較する場合に、これを使用します。

// cliext_hash_multimap_value_comp.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    Myhash_multimap::value_compare^ kcomp = c1.value_comp();

    System::Console::WriteLine("compare([L'a', 1], [L'a', 1]) = {0}",
        kcomp(Myhash_multimap::make_value(L'a', 1),
            Myhash_multimap::make_value(L'a', 1)));
    System::Console::WriteLine("compare([L'a', 1], [L'b', 2]) = {0}",
        kcomp(Myhash_multimap::make_value(L'a', 1),
            Myhash_multimap::make_value(L'b', 2)));
    System::Console::WriteLine("compare([L'b', 2], [L'a', 1]) = {0}",
        kcomp(Myhash_multimap::make_value(L'b', 2),
            Myhash_multimap::make_value(L'a', 1)));
    System::Console::WriteLine();
    return (0);
    }
compare([L'a', 1], [L'a', 1]) = True
compare([L'a', 1], [L'b', 2]) = True
compare([L'b', 2], [L'a', 1]) = False

hash_multimap::value_compare

2 つの要素値の順序付けデリゲートです。

構文

Microsoft::VisualC::StlClr::BinaryDelegate<generic_value, generic_value, bool>
    value_compare;

解説

この型は、値の引数の順序付けを決定するデリゲートのシノニムです。

// cliext_hash_multimap_value_compare.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    Myhash_multimap::value_compare^ kcomp = c1.value_comp();

    System::Console::WriteLine("compare([L'a', 1], [L'a', 1]) = {0}",
        kcomp(Myhash_multimap::make_value(L'a', 1),
            Myhash_multimap::make_value(L'a', 1)));
    System::Console::WriteLine("compare([L'a', 1], [L'b', 2]) = {0}",
        kcomp(Myhash_multimap::make_value(L'a', 1),
            Myhash_multimap::make_value(L'b', 2)));
    System::Console::WriteLine("compare([L'b', 2], [L'a', 1]) = {0}",
        kcomp(Myhash_multimap::make_value(L'b', 2),
            Myhash_multimap::make_value(L'a', 1)));
    System::Console::WriteLine();
    return (0);
    }
compare([L'a', 1], [L'a', 1]) = True
compare([L'a', 1], [L'b', 2]) = True
compare([L'b', 2], [L'a', 1]) = False

hash_multimap::value_type

要素の型。

構文

typedef generic_value value_type;

解説

型は、generic_value の同意語。

// cliext_hash_multimap_value_type.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;
int main()
    {
    Myhash_multimap c1;
    c1.insert(Myhash_multimap::make_value(L'a', 1));
    c1.insert(Myhash_multimap::make_value(L'b', 2));
    c1.insert(Myhash_multimap::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]" using value_type
    for (Myhash_multimap::iterator it = c1.begin(); it != c1.end(); ++it)
        {   // store element in value_type object
        Myhash_multimap::value_type val = *it;
        System::Console::Write("[{0} {1}] ", val->first, val->second);
        }
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]