Share via


map (STL/CLR)

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

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

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

どこで:

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

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

構文

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

パラメーター

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

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

必要条件

ヘッダー:<cliext/map>

名前空間cliext:

宣言

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

インターフェイス

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

解説

このオブジェクトは、個々のノードとして制御するシーケンスのストレージを割り当てたり解放したりします。 ノードのコンテンツを別のノードにコピーするのではなく、ノード間のリンクを変更することにより、順序付けを維持した状態で (ほぼ) バランスの取れたツリーに要素を挿入します。 つまり、残りの要素に影響を与えずに、要素を自由に挿入および削除できます。

オブジェクトは、型の格納されたデリゲート オブジェクトを呼び出すことによって、制御するシーケンスを並べ替えます map::key_compare。 格納されているデリゲート オブジェクトは、マップを構築するときに指定することができます。デリゲート オブジェクトを指定しない場合、既定値は比較 operator<(key_type, key_type) です。 この格納されているオブジェクトにアクセスするには、メンバー関数 map::key_compを呼び出します。

このようなデリゲート オブジェクトは、型 map::key_typeのキーに厳密な弱い順序を課す必要があります。 つまり、任意の 2 つのキー XY については、次のようになります。

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

key_comp()(X, Y) が true の場合は、key_comp()(Y, X) が false である必要があります。

key_comp()(X, Y) が true の場合、XY の前に順序付けられるものとされます。

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

被制御シーケンスで要素 XY の前に指定されている場合、key_comp()(Y, X) は false になります (既定のデリゲート オブジェクトの場合、キーの値が減少することはありません)。テンプレート クラス マップとは異なり、テンプレート クラス map のオブジェクトでは、すべての要素のキーが一意である必要はありません。 (2 つ以上のキーの順序付けを等しくすることができます)。

各要素には、個別のキーとマップされた値が含まれます。 シーケンスは、任意の要素の検索、挿入、および削除を対数時間で許可する方法で表されます。 つまり、演算の数は、シーケンス内の要素数の対数に比例します。 さらに、要素を挿入すると反復子が無効になり、要素を削除すると、削除された要素を指す反復子のみが無効になります。

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

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

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

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

メンバー

map::begin

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

構文

iterator begin();

解説

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

// cliext_map_begin.cpp
// compile with: /clr
#include <cliext/map>

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

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

    // inspect first two items
    Mymap::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]

map::clear

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

構文

void clear();

解説

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

// cliext_map_clear.cpp
// compile with: /clr
#include <cliext/map>

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

    // display contents " [a 1] [b 2] [c 3]"
    for each (Mymap::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(Mymap::make_value(L'a', 1));
    c1.insert(Mymap::make_value(L'b', 2));

    // display contents " [a 1] [b 2]"
    for each (Mymap::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

map::const_iterator

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

構文

typedef T2 const_iterator;

解説

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

// cliext_map_const_iterator.cpp
// compile with: /clr
#include <cliext/map>

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

    // display contents " [a 1] [b 2] [c 3]"
    Mymap::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]

map::const_reference

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

構文

typedef value_type% const_reference;

解説

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

// cliext_map_const_reference.cpp
// compile with: /clr
#include <cliext/map>

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

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

map::const_reverse_iterator

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

構文

typedef T4 const_reverse_iterator;

解説

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

// cliext_map_const_reverse_iterator.cpp
// compile with: /clr
#include <cliext/map>

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

    // display contents " [a 1] [b 2] [c 3]" reversed
    Mymap::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]

map::count

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

構文

size_type count(key_type key);

パラメーター

key
検索対象のキー値。

解説

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

// cliext_map_count.cpp
// compile with: /clr
#include <cliext/map>

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

    // display contents " [a 1] [b 2] [c 3]"
    for each (Mymap::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

map::difference_type

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

構文

typedef int difference_type;

解説

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

// cliext_map_difference_type.cpp
// compile with: /clr
#include <cliext/map>

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

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

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

    // compute negative difference
    diff = 0;
    for (Mymap::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

map::empty

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

構文

bool empty();

解説

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

// cliext_map_empty.cpp
// compile with: /clr
#include <cliext/map>

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

    // display contents " [a 1] [b 2] [c 3]"
    for each (Mymap::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

map::end

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

構文

iterator end();

解説

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

// cliext_map_end.cpp
// compile with: /clr
#include <cliext/map>

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

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

    // inspect last two items
    Mymap::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);
    }

map::equal_range

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

構文

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

パラメーター

key
検索対象のキー値。

解説

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

// cliext_map_equal_range.cpp
// compile with: /clr
#include <cliext/map>

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

    // display contents " [a 1] [b 2] [c 3]"
    for each (Mymap::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]

map::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_map_erase.cpp
// compile with: /clr
#include <cliext/map>

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

    // display contents " [a 1] [b 2] [c 3]"
    for each (cliext::map<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::map<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::map<wchar_t, int>::make_value(L'd', 4));
    c1.insert(cliext::map<wchar_t, int>::make_value(L'e', 5));
    for each (cliext::map<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

map::find

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

構文

iterator find(key_type key);

パラメーター

key
検索対象のキー値。

解説

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

// cliext_map_find.cpp
// compile with: /clr
#include <cliext/map>

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

    // display contents " [a 1] [b 2] [c 3]"
    for each (Mymap::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());

    Mymap::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

map::generic_container

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

構文

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

解説

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

// cliext_map_generic_container.cpp
// compile with: /clr
#include <cliext/map>

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

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

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

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

    // modify original and display generic
    c1.insert(Mymap::make_value(L'e', 5));
    for each (Mymap::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]

map::generic_iterator

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

構文

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

解説

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

// cliext_map_generic_iterator.cpp
// compile with: /clr
#include <cliext/map>

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

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

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

    // get an element and display it
    Mymap::generic_iterator gcit = gc1->begin();
    Mymap::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]

map::generic_reverse_iterator

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

構文

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

解説

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

// cliext_map_generic_reverse_iterator.cpp
// compile with: /clr
#include <cliext/map>

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

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

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

    // get an element and display it
    Mymap::generic_reverse_iterator gcit = gc1->rbegin();
    Mymap::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]

map::generic_value

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

構文

typedef GValue generic_value;

解説

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

// cliext_map_generic_value.cpp
// compile with: /clr
#include <cliext/map>

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

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

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

    // get an element and display it
    Mymap::generic_iterator gcit = gc1->begin();
    Mymap::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]

map::insert

要素を追加します。

構文

cliext::pair<iterator, bool> 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 を持つ要素の挿入を試行し、値 X のペアを返します。 X.second が true の場合、X.first によって、新しく挿入された要素が指定されます。それ以外の場合、X.first によって、順序付けが等しい既存の要素が指定されます。新しい要素は挿入されません。 1 つの要素を挿入する場合に、これを使用します。

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

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

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

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

// cliext_map_insert.cpp
// compile with: /clr
#include <cliext/map>

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

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

    // insert a single value, unique and duplicate
// insert a single value, success and failure
    Pairib pair1 = c1.insert(Mymap::make_value(L'x', 24));
    System::Console::WriteLine("insert([L'x' 24]) = [[{0} {1}] {2}]",
        pair1.first->first, pair1.first->second, pair1.second);

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

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

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

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

    // insert an enumeration
    Mymap c3;
    c3.insert(   // NOTE: cast is not needed
        (System::Collections::Generic::
            IEnumerable<Mymap::value_type>^)%c1);
    for each (Mymap::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] True]
insert([L'b' 2]) = [[b 2] False]
[a 1] [b 2] [c 3] [x 24]
insert(begin(), [L'y' 25]) = [y 25]
[a 1] [b 2] [c 3] [x 24] [y 25]
[a 1] [b 2] [c 3] [x 24]
[a 1] [b 2] [c 3] [x 24] [y 25]

map::iterator

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

構文

typedef T1 iterator;

解説

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

// cliext_map_iterator.cpp
// compile with: /clr
#include <cliext/map>

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

    // display contents " [a 1] [b 2] [c 3]"
    Mymap::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]

map::key_comp

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

構文

key_compare^key_comp();

解説

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

// cliext_map_key_comp.cpp
// compile with: /clr
#include <cliext/map>

typedef cliext::map<wchar_t, int> Mymap;
int main()
    {
    Mymap c1;
    Mymap::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
    Mymap 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') = False
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

map::key_compare

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

構文

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

解説

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

// cliext_map_key_compare.cpp
// compile with: /clr
#include <cliext/map>

typedef cliext::map<wchar_t, int> Mymap;
int main()
    {
    Mymap c1;
    Mymap::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
    Mymap 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') = False
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

map::key_type

順序付けキーの型です。

構文

typedef Key key_type;

解説

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

// cliext_map_key_type.cpp
// compile with: /clr
#include <cliext/map>

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

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

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

map::lower_bound

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

構文

iterator lower_bound(key_type key);

パラメーター

key
検索対象のキー値。

解説

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

// cliext_map_lower_bound.cpp
// compile with: /clr
#include <cliext/map>

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

    // display contents " [a 1] [b 2] [c 3]"
    for each (Mymap::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());

    Mymap::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]

map::make_value

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

構文

static value_type make_value(key_type key, mapped_type mapped);

パラメーター

key
使用するキー値。

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

解説

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

// cliext_map_make_value.cpp
// compile with: /clr
#include <cliext/map>

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

    // display contents " [a 1] [b 2] [c 3]"
    for each (Mymap::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]

map::map

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

構文

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

パラメーター

first
挿入する範囲の先頭。

last
挿入する範囲の末尾。

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

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

解説

コンストラクター:

map();

既定の順序付けの述語 key_compare() を使って、要素のない被制御シーケンスを初期化します。 既定の順序付けの述語を使って、空の初期被制御シーケンスを指定する場合に使います。

コンストラクター:

explicit map(key_compare^ pred);

は、順序付け述語 predを使用して、要素なしで制御シーケンスを初期化します。 それを使って、指定した順序付けの述語で、空の初期被制御シーケンスを指定します。

コンストラクター:

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

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

コンストラクター:

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

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

コンストラクター:

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

既定の順序付けの述語を使用して、シーケンス [first, last) で被制御シーケンスを初期化します。 既定の順序付けの述語を使って、別のシーケンスのコピーを被制御シーケンスにする場合に使用します。

コンストラクター:

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

は、順序付け述語predを使用して、シーケンス [first, last) を使用して、制御シーケンスを初期化します。 指定した順序付けの述語を使って、別のシーケンスのコピーを被制御シーケンスにする場合に使用します。

コンストラクター:

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

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

コンストラクター:

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

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

// cliext_map_construct.cpp
// compile with: /clr
#include <cliext/map>

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

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

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

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

    // construct with an iterator range
    Mymap c3(c1.begin(), c1.end());
    for each (Mymap::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
    Mymap c4(c1.begin(), c1.end(),
        cliext::greater_equal<wchar_t>());
    for each (Mymap::value_type elem in c4)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

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

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

    // construct by copying a container handle
    Mymap c8(%c3);
    for each (Mymap::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
[c 3] [b 2] [a 1]
[a 1] [b 2] [c 3]
[c 3] [b 2] [a 1]
[a 1] [b 2] [c 3]
[c 3] [b 2] [a 1]
[c 3] [b 2] [a 1]
[a 1] [b 2] [c 3]

map::mapped_type

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

構文

typedef Mapped mapped_type;

解説

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

// cliext_map_mapped_type.cpp
// compile with: /clr
#include <cliext/map>

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

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

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

map::operator=

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

構文

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

パラメーター

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

解説

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

// cliext_map_operator_as.cpp
// compile with: /clr
#include <cliext/map>

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

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

    // assign to a new container
    Mymap c2;
    c2 = c1;
    // display contents " [a 1] [b 2] [c 3]"
    for each (Mymap::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]

map::operator[]

キーを関連するマップされた値にマップします。

構文

mapped_type operator[](key_type key);

パラメーター

key
検索対象のキー値。

解説

メンバー関数は、同等の順序 keyを持つ要素を見つけようとします。 見つけた場合は、関連するマップされた値を返します。それ以外の場合は、value_type(key, mapped_type()) を挿入して、関連する (既定の) マップされた値が返されます。 関連するキーを指定してマップされた値を参照したり、キーが見つからないとき、確実にエントリが存在するようにしたい場合に使います。

// cliext_map_operator_sub.cpp
// compile with: /clr
#include <cliext/map>

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

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

    System::Console::WriteLine("c1[{0}] = {1}",
        L'A', c1[L'A']);
    System::Console::WriteLine("c1[{0}] = {1}",
        L'b', c1[L'b']);

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

    // alter mapped values and redisplay
    c1[L'A'] = 10;
    c1[L'c'] = 13;
    for each (Mymap::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]
c1[A] = 0
c1[b] = 2
[A 0] [a 1] [b 2] [c 3]
[A 10] [a 1] [b 2] [c 13]

map::rbegin

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

構文

reverse_iterator rbegin();

解説

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

// cliext_map_rbegin.cpp
// compile with: /clr
#include <cliext/map>

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

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

    // inspect first two items in reversed sequence
    Mymap::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]

map::reference

要素への参照の型です。

構文

typedef value_type% reference;

解説

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

// cliext_map_reference.cpp
// compile with: /clr
#include <cliext/map>

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

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

map::rend

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

構文

reverse_iterator rend();

解説

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

// cliext_map_rend.cpp
// compile with: /clr
#include <cliext/map>

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

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

    // inspect first two items in reversed sequence
    Mymap::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]

map::reverse_iterator

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

構文

typedef T3 reverse_iterator;

解説

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

// cliext_map_reverse_iterator.cpp
// compile with: /clr
#include <cliext/map>

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

    // display contents " [a 1] [b 2] [c 3]" reversed
    Mymap::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]

map::size

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

構文

size_type size();

解説

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

// cliext_map_size.cpp
// compile with: /clr
#include <cliext/map>

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

    // display contents " [a 1] [b 2] [c 3]"
    for each (Mymap::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(Mymap::make_value(L'd', 4));
    c1.insert(Mymap::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

map::size_type

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

構文

typedef int size_type;

解説

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

// cliext_map_size_type.cpp
// compile with: /clr
#include <cliext/map>

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

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

    // compute positive difference
    Mymap::size_type diff = 0;
    for (Mymap::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

map::swap

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

構文

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

パラメーター

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

解説

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

// cliext_map_swap.cpp
// compile with: /clr
#include <cliext/map>

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

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

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

    for each (Mymap::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]

map::to_array

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

構文

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

解説

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

// cliext_map_to_array.cpp
// compile with: /clr
#include <cliext/map>

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

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

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

    // display the earlier array copy
    for each (Mymap::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]

map::upper_bound

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

構文

iterator upper_bound(key_type key);

パラメーター

key
検索対象のキー値。

解説

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

// cliext_map_upper_bound.cpp
// compile with: /clr
#include <cliext/map>

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

    // display contents " [a 1] [b 2] [c 3]"
    for each (Mymap::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());

    Mymap::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]

map::value_comp

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

構文

value_compare^ value_comp();

解説

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

// cliext_map_value_comp.cpp
// compile with: /clr
#include <cliext/map>

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

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

map::value_compare

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

構文

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

解説

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

// cliext_map_value_compare.cpp
// compile with: /clr
#include <cliext/map>

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

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

map::value_type

要素の型。

構文

typedef generic_value value_type;

解説

型は、generic_value の同意語。

// cliext_map_value_type.cpp
// compile with: /clr
#include <cliext/map>

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

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

operator!= (map) (STL/CLR)

リストが等しくないかどうかの比較です。

構文

template<typename Key,
    typename Mapped>
    bool operator!=(map<Key, Mapped>% left,
        map<Key, Mapped>% right);

パラメーター

left
比較する左のコンテナー。

right
比較する右のコンテナー。

解説

この演算子関数は、!(left == right) を返します。 これを使用して、2 つのマップが要素ごとに比較される場合とright同じ順序になっていないかどうかをleftテストします。

// cliext_map_operator_ne.cpp
// compile with: /clr
#include <cliext/map>

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

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

    // assign to a new container
    Mymap c2;
    c2.insert(Mymap::make_value(L'a', 1));
    c2.insert(Mymap::make_value(L'b', 2));
    c2.insert(Mymap::make_value(L'd', 4));

    // display contents " [a 1] [b 2] [d 4]"
    for each (Mymap::value_type elem in c2)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    System::Console::WriteLine("[a b c] != [a b c] is {0}",
        c1 != c1);
    System::Console::WriteLine("[a b c] != [a b d] is {0}",
        c1 != c2);
    return (0);
    }
[a 1] [b 2] [c 3]
[a 1] [b 2] [d 4]
[a b c] != [a b c] is False
[a b c] != [a b d] is True

operator< (map)

リストがより小さいかどうかの比較です。

構文

template<typename Key,
    typename Mapped>
    bool operator<(map<Key, Mapped>% left,
        map<Key, Mapped>% right);

パラメーター

left
比較する左のコンテナー。

right
比較する右のコンテナー。

解説

演算子関数は true を返します場合は、最も低い位置i!(right[i] < left[i])の場合は true を返しますleft[i] < right[i]。 それ以外の場合は left->size() < right->size()を返します。 この演算子を使用して、2 つのマップが要素ごとに比較される前にright順序付けされているかどうかをleftテストします。

// cliext_map_operator_lt.cpp
// compile with: /clr
#include <cliext/map>

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

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

    // assign to a new container
    Mymap c2;
    c2.insert(Mymap::make_value(L'a', 1));
    c2.insert(Mymap::make_value(L'b', 2));
    c2.insert(Mymap::make_value(L'd', 4));

    // display contents " [a 1] [b 2] [d 4]"
    for each (Mymap::value_type elem in c2)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    System::Console::WriteLine("[a b c] < [a b c] is {0}",
        c1 < c1);
    System::Console::WriteLine("[a b c] < [a b d] is {0}",
        c1 < c2);
    return (0);
    }
[a 1] [b 2] [c 3]
[a 1] [b 2] [d 4]
[a b c] < [a b c] is False
[a b c] < [a b d] is True

operator<= (map)

リストが以下であるかどうかの比較です。

構文

template<typename Key,
    typename Mapped>
    bool operator<=(map<Key, Mapped>% left,
        map<Key, Mapped>% right);

パラメーター

left
比較する左のコンテナー。

right
比較する右のコンテナー。

解説

この演算子関数は、!(right < left) を返します。 これを使用して、2 つのマップが要素ごとに比較される後に順序付けrightされていないかどうかをleftテストします。

// cliext_map_operator_le.cpp
// compile with: /clr
#include <cliext/map>

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

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

    // assign to a new container
    Mymap c2;
    c2.insert(Mymap::make_value(L'a', 1));
    c2.insert(Mymap::make_value(L'b', 2));
    c2.insert(Mymap::make_value(L'd', 4));

    // display contents " [a 1] [b 2] [d 4]"
    for each (Mymap::value_type elem in c2)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    System::Console::WriteLine("[a b c] <= [a b c] is {0}",
        c1 <= c1);
    System::Console::WriteLine("[a b d] <= [a b c] is {0}",
        c2 <= c1);
    return (0);
    }
[a 1] [b 2] [c 3]
[a 1] [b 2] [d 4]
[a b c] <= [a b c] is True
[a b d] <= [a b c] is False

operator== (map)

リストが等しいかどうかの比較です。

構文

template<typename Key,
    typename Mapped>
    bool operator==(map<Key, Mapped>% left,
        map<Key, Mapped>% right);

パラメーター

left
比較する左のコンテナー。

right
比較する右のコンテナー。

解説

演算子関数は、制御されるシーケンスの長さが同じで、各位置ileft[i] == right[i]に対してleftright同じ場合にのみ true を返します。 これを使用して、2 つのマップが要素ごとに比較される場合とright同じ順序になっているかどうかをleftテストします。

// cliext_map_operator_eq.cpp
// compile with: /clr
#include <cliext/map>

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

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

    // assign to a new container
    Mymap c2;
    c2.insert(Mymap::make_value(L'a', 1));
    c2.insert(Mymap::make_value(L'b', 2));
    c2.insert(Mymap::make_value(L'd', 4));

    // display contents " [a 1] [b 2] [d 4]"
    for each (Mymap::value_type elem in c2)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    System::Console::WriteLine("[a b c] == [a b c] is {0}",
        c1 == c1);
    System::Console::WriteLine("[a b c] == [a b d] is {0}",
        c1 == c2);
    return (0);
    }
[a 1] [b 2] [c 3]
[a 1] [b 2] [d 4]
[a b c] == [a b c] is True
[a b c] == [a b d] is False

operator> (map)

リストがより大きいかどうかの比較です。

構文

template<typename Key,
    typename Mapped>
    bool operator>(map<Key, Mapped>% left,
        map<Key, Mapped>% right);

パラメーター

left
比較する左のコンテナー。

right
比較する右のコンテナー。

解説

この演算子関数は、right < left を返します。 これを使用して、2 つのマップが要素ごとに比較された後に順序付けrightされているかどうかをleftテストします。

// cliext_map_operator_gt.cpp
// compile with: /clr
#include <cliext/map>

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

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

    // assign to a new container
    Mymap c2;
    c2.insert(Mymap::make_value(L'a', 1));
    c2.insert(Mymap::make_value(L'b', 2));
    c2.insert(Mymap::make_value(L'd', 4));

    // display contents " [a 1] [b 2] [d 4]"
    for each (Mymap::value_type elem in c2)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    System::Console::WriteLine("[a b c] > [a b c] is {0}",
        c1 > c1);
    System::Console::WriteLine("[a b d] > [a b c] is {0}",
        c2 > c1);
    return (0);
    }
[a 1] [b 2] [c 3]
[a 1] [b 2] [d 4]
[a b c] > [a b c] is False
[a b d] > [a b c] is True

operator>= (map)

リストが以上であるかどうかの比較です。

構文

template<typename Key,
    typename Mapped>
    bool operator>=(map<Key, Mapped>% left,
        map<Key, Mapped>% right);

パラメーター

left
比較する左のコンテナー。

right
比較する右のコンテナー。

解説

この演算子関数は、!(left < right) を返します。 これを使用して、2 つのマップが要素ごとに比較される前にright順序付けされていないかどうかをleftテストします。

// cliext_map_operator_ge.cpp
// compile with: /clr
#include <cliext/map>

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

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

    // assign to a new container
    Mymap c2;
    c2.insert(Mymap::make_value(L'a', 1));
    c2.insert(Mymap::make_value(L'b', 2));
    c2.insert(Mymap::make_value(L'd', 4));

    // display contents " [a 1] [b 2] [d 4]"
    for each (Mymap::value_type elem in c2)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    System::Console::WriteLine("[a b c] >= [a b c] is {0}",
        c1 >= c1);
    System::Console::WriteLine("[a b c] >= [a b d] is {0}",
        c1 >= c2);
    return (0);
    }
[a 1] [b 2] [c 3]
[a 1] [b 2] [d 4]
[a b c] >= [a b c] is True
[a b c] >= [a b d] is False