list (STL/CLR)

このテンプレート クラスは、双方向にアクセスできる可変長の要素シーケンスを制御するオブジェクトを表します。 list コンテナーを使って、要素シーケンスを、ノードの双方向リンク リストとして管理します。各ノードには 1 つの要素が格納されます。

以降の説明では、GValueValue と同じですが、後者が ref 型の場合は Value^ となります。

構文

template<typename Value>
    ref class list
        :   public
        System::ICloneable,
        System::Collections::IEnumerable,
        System::Collections::ICollection,
        System::Collections::Generic::IEnumerable<GValue>,
        System::Collections::Generic::ICollection<GValue>,
        Microsoft::VisualC::StlClr::IList<GValue>
    { ..... };

パラメーター

Value
被制御シーケンス内の要素の型。

必要条件

ヘッダー:<cliext/list>

名前空間: cliext

宣言

型の定義 説明
list::const_iterator (STL/CLR) 被制御シーケンスの定数反復子の型です。
list::const_reference (STL/CLR) 要素への定数参照の型です。
list::const_reverse_iterator (STL/CLR) 被制御シーケンスの定数反転反復子の型です。
list::difference_type (STL/CLR) 2 つの要素間の距離を表す、符号付きの型です。
list::generic_container (STL/CLR) コンテナーのジェネリック インターフェイスの型です。
list::generic_iterator (STL/CLR) コンテナーのジェネリック インターフェイスの反復子の型です。
list::generic_reverse_iterator (STL/CLR) コンテナーのジェネリック インターフェイスの反転反復子の型です。
list::generic_value (STL/CLR) コンテナーのジェネリック インターフェイスの要素の型です。
list::iterator (STL/CLR) 被制御シーケンスの反復子の型です。
list::reference (STL/CLR) 要素への参照の型です。
list::reverse_iterator (STL/CLR) 被制御シーケンスの反転反復子の型です。
list::size_type (STL/CLR) 2 つの要素間の距離を表す、符号付きの型です。
list::value_type (STL/CLR) 要素の型。
メンバー関数 説明
list::assign (STL/CLR) すべての要素を置換します。
list::back (STL/CLR) 最後の要素にアクセスします。
list::begin (STL/CLR) 被制御シーケンスの先頭を指定します。
list::clear (STL/CLR) すべての要素を削除します。
list::empty (STL/CLR) 要素が存在しないかどうかをテストします。
list::end (STL/CLR) 被制御シーケンスの末尾を指定します。
list::erase (STL/CLR) 指定した位置にある要素を削除します。
list::front (STL/CLR) 最初の要素にアクセスします。
list::insert (STL/CLR) 指定した位置に要素を追加します。
list::list (STL/CLR) コンテナー オブジェクトを構築します。
list::merge (STL/CLR) 順序指定された 2 つの制御シーケンスをマージします。
list::pop_back (STL/CLR) 最後の要素を削除します。
list::pop_front (STL/CLR) 最初の要素を削除します。
list::push_back (STL/CLR) 新規に末尾の要素を追加します。
list::push_front (STL/CLR) 新しい最初の要素を追加します。
list::rbegin (STL/CLR) 反転被制御シーケンスの先頭を指定します。
list::remove (STL/CLR) 指定した値を持つ要素を削除します。
list::remove_if (STL/CLR) 指定したテストに合格した要素を削除します。
list::rend (STL/CLR) 反転被制御シーケンスの末尾を指定します。
list::resize (STL/CLR) 要素の数を変更します。
list::reverse (STL/CLR) 被制御シーケンスを反転させます。
list::size (STL/CLR) 要素の数をカウントします。
list::sort (STL/CLR) 制御されたシーケンスを並べ替えます。
list::splice (STL/CLR) ノード間のリンクを再接合します。
list::swap (STL/CLR) 2 つのコンテナーのコンテンツを交換します。
list::to_array (STL/CLR) 被制御シーケンスを新しい配列にコピーします。
list::unique (STL/CLR) 指定されたテストに合格した隣接する要素を削除します。
プロパティ 説明
list::back_item (STL/CLR) 最後の要素にアクセスします。
list::front_item (STL/CLR) 最初の要素にアクセスします。
Operator 説明
list::operator= (STL/CLR) 被制御シーケンスを置き換えます。
operator!= (list) (STL/CLR) list オブジェクトが別の list オブジェクトと等しくないかどうかを判断します。
operator< (list) (STL/CLR) list オブジェクトが別の list オブジェクトより小さいかどうかを確認します。
operator<= (list) (STL/CLR) list オブジェクトが別の list オブジェクト以下かどうかを判断します。
operator== (list) (STL/CLR) list オブジェクトが別の list オブジェクトと等しいかどうかを判断します。
operator> (list) (STL/CLR) list オブジェクトが別の list オブジェクトより大きいかどうかを判断します。
operator>= (list) (STL/CLR) list オブジェクトが別の list オブジェクト以上かどうかを判断します。

インターフェイス

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

解説

このオブジェクトでは、双方向リンク リスト内の個々のノードとしての被制御シーケンスに対してストレージの割り当てと解放を行います。 コンテンツをノード間でコピーするのではなく、ノード間のリンクを変更することにより、要素を再配置します。 つまり、残りの要素に影響を与えずに、要素を自由に挿入および削除できます。 したがって、リストは、テンプレート クラス queue (STL/CLR) またはテンプレート クラス stack (STL/CLR) の基になるコンテナーに適しています。

list オブジェクトは双方向反復子をサポートしています。つまり、被制御シーケンス内の要素を指定する反復子を使って、隣接する要素に進むことができます。 特別なヘッド ノードは、list::end (STL/CLR)() で返される反復子に対応します。 この反復子をデクリメントすると、被制御シーケンス内の最後の要素 (存在する場合) に到達できます。 list 反復子をインクリメントしてヘッド ノードに到達すると、end() と等しいと判定されます。 ただし、end() によって返される反復子を逆参照することはできません。

数値で位置を指定して list 要素を直接参照することはできないので注意してください。これには、ランダム アクセス反復子が必要です。 したがって、list は、テンプレート クラス priority_queue (STL/CLR) の基になるコンテナーとしては使用 "できません"。

list 反復子は、関連付けられた list ノードへのハンドルを格納し、同様にして関連付けられたコンテナーへのハンドルを格納します。 反復子は、関連付けられているコンテナー オブジェクトでのみ使用できます。 list 反復子は、関連付けられた list ノードが何らかの list に関連付けられている限り、有効です。 さらに、有効な反復子は逆参照できます。この反復子を使うと、指定した要素の値にアクセスしたり、値を変更したりできます (end() と等しくない場合のみ)。

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

メンバー

list::assign (STL/CLR)

すべての要素を置換します。

構文

void assign(size_type count, value_type val);
template<typename InIt>
    void assign(InIt first, InIt last);
void assign(System::Collections::Generic::IEnumerable<Value>^ right);

パラメーター

count
挿入する要素の数。

first
挿入する範囲の先頭。

last
挿入する範囲の末尾。

right
挿入する列挙型。

val
挿入する要素の値。

解説

最初のメンバー関数は、被制御シーケンスを、値 valcount 個の要素の繰り返しで置き換えます。 これを使って、すべて同じ値を持つ要素をコンテナーに格納します。

InIt が整数型である場合、2 番目のメンバー関数は assign((size_type)first, (value_type)last) と同じように動作します。 それ以外の場合は、被制御シーケンスをシーケンス [first, last) で置き換えます。 これを使用して、被制御シーケンスを別のシーケンスにコピーします。

3 番目のメンバー関数は、被制御シーケンスを列挙子 right によって指定されたシーケンスに置き換えます。 これを使用して、被制御シーケンスを列挙子によって記述されたシーケンスのコピーにします。

// cliext_list_assign.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // assign a repetition of values
    cliext::list<wchar_t> c2;
    c2.assign(6, L'x');
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign an iterator range
    cliext::list<wchar_t>::iterator it = c1.end();
    c2.assign(c1.begin(), --it);
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign an enumeration
    c2.assign(   // NOTE: cast is not needed
        (System::Collections::Generic::IEnumerable<wchar_t>^)%c1);
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
x x x x x x
a b
a b c

list::back (STL/CLR)

最後の要素にアクセスします。

構文

reference back();

解説

このメンバー関数は、被制御シーケンスの最後の要素への参照を返します。これを空にすることはできません。 最後の要素が存在することがわかっている場合は、それにアクセスするために使用します。

// cliext_list_back.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // inspect last item
    System::Console::WriteLine("back() = {0}", c1.back());

    // alter last item and reinspect
    c1.back() = L'x';
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
back() = c
a b x

list::back_item (STL/CLR)

最後の要素にアクセスします。

構文

property value_type back_item;

解説

このプロパティは、被制御シーケンスの最後の要素 (これを空にすることはできません) にアクセスします。 これは、最後の要素が存在することがわかっている場合に、その読み取りまたは書き込みを行うために使用します。

// cliext_list_back_item.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // inspect last item
    System::Console::WriteLine("back_item = {0}", c1.back_item);

    // alter last item and reinspect
    c1.back_item = L'x';
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
back_item = c
a b x

list::begin (STL/CLR)

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

構文

iterator begin();

解説

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

// cliext_list_begin.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // inspect first two items
    cliext::list<wchar_t>::iterator it = c1.begin();
    System::Console::WriteLine("*begin() = {0}", *it);
    System::Console::WriteLine("*++begin() = {0}", *++it);

    // alter first two items and reinspect
    *--it = L'x';
    *++it = L'y';
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
*begin() = a
*++begin() = b
x y c

list::clear (STL/CLR)

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

構文

void clear();

解説

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

// cliext_list_clear.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

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

    // add elements and clear again
    c1.push_back(L'a');
    c1.push_back(L'b');

    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    c1.clear();
    System::Console::WriteLine("size() = {0}", c1.size());
    return (0);
    }
a b c
size() = 0
a b
size() = 0

list::const_iterator (STL/CLR)

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

構文

typedef T2 const_iterator;

解説

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

// cliext_list_const_iterator.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    cliext::list<wchar_t>::const_iterator cit = c1.begin();
    for (; cit != c1.end(); ++cit)
        System::Console::Write("{0} ", *cit);
    System::Console::WriteLine();
    return (0);
    }
a b c

list::const_reference (STL/CLR)

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

構文

typedef value_type% const_reference;

解説

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

// cliext_list_const_reference.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    cliext::list<wchar_t>::const_iterator cit = c1.begin();
    for (; cit != c1.end(); ++cit)
        {   // get a const reference to an element
        cliext::list<wchar_t>::const_reference cref = *cit;
        System::Console::Write("{0} ", cref);
        }
    System::Console::WriteLine();
    return (0);
    }
a b c

list::const_reverse_iterator (STL/CLR)

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

構文

typedef T4 const_reverse_iterator;

解説

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

// cliext_list_const_reverse_iterator.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c" reversed
    cliext::list<wchar_t>::const_reverse_iterator crit = c1.rbegin();
    cliext::list<wchar_t>::const_reverse_iterator crend = c1.rend();
    for (; crit != crend; ++crit)
        System::Console::Write("{0} ", *crit);
    System::Console::WriteLine();
    return (0);
    }
c b a

list::difference_type (STL/CLR)

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

構文

typedef int difference_type;

解説

この型は、署名された要素の数を表します。

// cliext_list_difference_type.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

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

    // compute negative difference
    diff = 0;
    for (cliext::list<wchar_t>::iterator it = c1.end();
        it != c1.begin(); --it) --diff;
    System::Console::WriteLine("begin()-end() = {0}", diff);
    return (0);
    }
a b c
end()-begin() = 3
begin()-end() = -3

list::empty (STL/CLR)

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

構文

bool empty();

解説

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

// cliext_list_empty.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    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 b c
size() = 3
empty() = False
size() = 0
empty() = True

list::end (STL/CLR)

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

構文

iterator end();

解説

このメンバー関数は、被制御シーケンスの末尾を越えたところを示すランダムアクセス反復子を返します。 これを使って被制御シーケンスの末尾を指定する反復子を取得します。この状態は、被制御シーケンスの長さが変わっても変化することはありません。

// cliext_list_end.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // inspect last two items
    cliext::list<wchar_t>::iterator it = c1.end();
    --it;
    System::Console::WriteLine("*-- --end() = {0}", *--it);
    System::Console::WriteLine("*--end() = {0}", *++it);

    // alter first two items and reinspect
    *--it = L'x';
    *++it = L'y';
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
*-- --end() = b
*--end() = c
a x y

list::erase (STL/CLR)

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

構文

iterator erase(iterator where);
iterator erase(iterator first, iterator last);

パラメーター

first
消去する範囲の先頭。

last
消去する範囲の末尾。

where
消去する要素。

解説

1 番目のメンバー関数は、where によってポイントされている被制御シーケンスの要素を削除します。 1 つの要素を削除する場合に使います。

2 番目のメンバー関数は、範囲 [first, last) の被制御シーケンスの要素を削除します。 0 個以上の連続する要素を削除する場合に、これを使用します。

両方のメンバー関数が、削除された要素の後の最初の残存要素を指定する反復子を返します。このような要素が存在しない場合は、list::end (STL/CLR)() が返されます。

要素を消去する場合、要素のコピー数は、消去の終わりとシーケンスの近端の間にある要素の数に比例します。 (シーケンスの両端で 1 つ以上の要素を消去すると、要素のコピーは行われません。)

// cliext_list_erase.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // erase an element and reinspect
    System::Console::WriteLine("erase(begin()) = {0}",
        *c1.erase(c1.begin()));

    // add elements and display " b c d e"
    c1.push_back(L'd');
    c1.push_back(L'e');
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // erase all but end
    cliext::list<wchar_t>::iterator it = c1.end();
    System::Console::WriteLine("erase(begin(), end()-1) = {0}",
        *c1.erase(c1.begin(), --it));
    System::Console::WriteLine("size() = {0}", c1.size());
    return (0);
    }
a b c
erase(begin()) = b
b c d e
erase(begin(), end()-1) = e
size() = 1

list::front (STL/CLR)

最初の要素にアクセスします。

構文

reference front();

解説

このメンバー関数は、被制御シーケンスの最初の要素への参照を返します。被制御シーケンスを空にすることはできません。 これは、最初の要素が存在することがわかっている場合に、その読み取りまたは書き込みを行うために使用します。

// cliext_list_front.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // inspect first item
    System::Console::WriteLine("front() = {0}", c1.front());

    // alter first item and reinspect
    c1.front() = L'x';
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
front() = a
x b c

list::front_item (STL/CLR)

最初の要素にアクセスします。

構文

property value_type front_item;

解説

このプロパティは、被制御シーケンスの最初の要素 (これを空にすることはできません) にアクセスします。 これは、最初の要素が存在することがわかっている場合に、その読み取りまたは書き込みを行うために使用します。

// cliext_list_front_item.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // inspect first item
    System::Console::WriteLine("front_item = {0}", c1.front_item);

    // alter first item and reinspect
    c1.front_item = L'x';
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
front_item = a
x b c

list::generic_container (STL/CLR)

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

構文

typedef Microsoft::VisualC::StlClr::
    IList<generic_value>
    generic_container;

解説

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

// cliext_list_generic_container.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct a generic container
    cliext::list<wchar_t>::generic_container^ gc1 = %c1;
    for each (wchar_t elem in gc1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // modify generic and display original
    gc1->insert(gc1->end(), L'd');
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // modify original and display generic
    c1.push_back(L'e');

    System::Collections::IEnumerator^ enum1 =
        gc1->GetEnumerator();
    while (enum1->MoveNext())
        System::Console::Write("{0} ", enum1->Current);
    System::Console::WriteLine();
    return (0);
    }
a b c
a b c
a b c d
a b c d e

list::generic_iterator (STL/CLR)

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

構文

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

解説

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

// cliext_list_generic_iterator.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct a generic container
    cliext::list<wchar_t>::generic_container^ gc1 = %c1;
    for each (wchar_t elem in gc1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // modify generic and display original
    cliext::list<wchar_t>::generic_iterator gcit = gc1->begin();
    cliext::list<wchar_t>::generic_value gcval = *gcit;
    *++gcit = gcval;
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
a b c
a a c

list::generic_reverse_iterator (STL/CLR)

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

構文

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

解説

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

// cliext_list_generic_reverse_iterator.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct a generic container
    cliext::list<wchar_t>::generic_container^ gc1 = %c1;
    for each (wchar_t elem in gc1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // modify generic and display original
    cliext::list<wchar_t>::generic_reverse_iterator gcit = gc1->rbegin();
    cliext::list<wchar_t>::generic_value gcval = *gcit;
    *++gcit = gcval;
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
a b c
a c c

list::generic_value (STL/CLR)

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

構文

typedef GValue generic_value;

解説

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

// cliext_list_generic_value.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct a generic container
    cliext::list<wchar_t>::generic_container^ gc1 = %c1;
    for each (wchar_t elem in gc1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // modify generic and display original
    cliext::list<wchar_t>::generic_iterator gcit = gc1->begin();
    cliext::list<wchar_t>::generic_value gcval = *gcit;
    *++gcit = gcval;
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
a b c
a a c

list::insert (STL/CLR)

指定した位置に要素を追加します。

構文

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

パラメーター

count
挿入する要素の数。

first
挿入する範囲の先頭。

last
挿入する範囲の末尾。

right
挿入する列挙型。

val
挿入する要素の値。

where
コンテナー内の挿入位置 (この前)。

解説

各メンバー関数は、被制御シーケンス内の where によって示されている要素の前に、残りのオペランドによって指定されたシーケンスを挿入します。

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

2 番目のメンバー関数は、値 val の要素を count 個挿入します。 すべてが同じ値のコピーである 0 個以上の連続する要素を挿入するために使用します。

InIt が整数型である場合、3 番目のメンバー関数は insert(where, (size_type)first, (value_type)last) と同じように動作します。 それ以外の場合は、シーケンス [first, last) が挿入されます。 別のシーケンスからコピーした 0 個以上の連続する要素を挿入する場合に、これを使用します。

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

1 つの要素を挿入する場合、要素のコピー数は、挿入ポイントとシーケンスの近端の間にある要素の数に比例します。 (シーケンスのいずれかの末尾に 1 つ以上の要素を挿入する場合、要素のコピーは発生しません)。入力反復子の場合 InIt 、3 番目のメンバー関数は、シーケンス内の各要素に対して 1 つの挿入を効果的に実行します。 それ以外で、N 要素を挿入する場合、要素のコピー数は、挿入ポイントとシーケンスの近端の間にある要素の数に N を加えた数に比例します。

// cliext_list_insert.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // insert a single value using iterator
    cliext::list<wchar_t>::iterator it = c1.begin();
    System::Console::WriteLine("insert(begin()+1, L'x') = {0}",
        *c1.insert(++it, L'x'));
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // insert a repetition of values
    cliext::list<wchar_t> c2;
    c2.insert(c2.begin(), 2, L'y');
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // insert an iterator range
    it = c1.end();
    c2.insert(c2.end(), c1.begin(), --it);
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // insert an enumeration
    c2.insert(c2.begin(),   // NOTE: cast is not needed
        (System::Collections::Generic::IEnumerable<wchar_t>^)%c1);
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // insert a single value using index
    it = c2.begin();
    ++it, ++it, ++it;
    c2.insert(it, L'z');
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    return (0);
    }
a b c
insert(begin()+1, L'x') = x
a x b c
y y
y y a x b
a x b c y y a x b

list::iterator (STL/CLR)

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

構文

typedef T1 iterator;

解説

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

// cliext_list_iterator.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    cliext::list<wchar_t>::iterator it = c1.begin();
    for (; it != c1.end(); ++it)
        System::Console::Write("{0} ", *it);
    System::Console::WriteLine();

    // alter first element and redisplay
    it = c1.begin();
    *it = L'x';
    for (; it != c1.end(); ++it)
        System::Console::Write("{0} ", *it);
    System::Console::WriteLine();
    return (0);
    }
a b c
x b c

list::list (STL/CLR)

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

構文

list();
list(list<Value>% right);
list(list<Value>^ right);
explicit list(size_type count);
list(size_type count, value_type val);
template<typename InIt>
    list(InIt first, InIt last);
list(System::Collections::Generic::IEnumerable<Value>^ right);

パラメーター

count
挿入する要素の数。

first
挿入する範囲の先頭。

last
挿入する範囲の末尾。

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

val
挿入する要素の値。

解説

コンストラクター:

list();

は、要素なしで被制御シーケンスを初期化します。 これを使用して、空の初期被制御シーケンスを指定します。

コンストラクター:

list(list<Value>% right);

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

コンストラクター:

list(list<Value>^ right);

は、被制御シーケンスをシーケンス [right->begin(), right->end()) で初期化します。 これを使用して、ハンドルが right のリスト オブジェクトによって制御されるシーケンスのコピーである最初の被制御シーケンスを指定します。

コンストラクター:

explicit list(size_type count);

は、それぞれ値が value_type()count 個の要素で被制御シーケンスを初期化します。 これを使って、すべて既定値を持つ要素をコンテナーに格納します。

コンストラクター:

list(size_type count, value_type val);

は、それぞれ値が valcount 個の要素で被制御シーケンスを初期化します。 これを使って、すべて同じ値を持つ要素をコンテナーに格納します。

コンストラクター:

template<typename InIt>

list(InIt first, InIt last);

は、被制御シーケンスをシーケンス [first, last) で初期化します。 これを使用して、被制御シーケンスを別のシーケンスのコピーにします。

コンストラクター:

list(System::Collections::Generic::IEnumerable<Value>^ right);

は、列挙子 right によって指定されたシーケンスで被制御シーケンスを初期化します。 これを使用して、被制御シーケンスを列挙子によって記述された別のシーケンスのコピーにします。

// cliext_list_construct.cpp
// compile with: /clr
#include <cliext/list>

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

    // construct with a repetition of default values
    cliext::list<wchar_t> c2(3);
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", (int)elem);
    System::Console::WriteLine();

    // construct with a repetition of values
    cliext::list<wchar_t> c3(6, L'x');
    for each (wchar_t elem in c3)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct with an iterator range
    cliext::list<wchar_t>::iterator it = c3.end();
    cliext::list<wchar_t> c4(c3.begin(), --it);
    for each (wchar_t elem in c4)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct with an enumeration
    cliext::list<wchar_t> c5(   // NOTE: cast is not needed
        (System::Collections::Generic::IEnumerable<wchar_t>^)%c3);
    for each (wchar_t elem in c5)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct by copying another container
    cliext::list<wchar_t> c7(c3);
    for each (wchar_t elem in c7)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct by copying a container handle
    cliext::list<wchar_t> c8(%c3);
    for each (wchar_t elem in c8)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    return (0);
    }
size() = 0
0 0 0
x x x x x x
x x x x x
x x x x x x
x x x x x x
x x x x x x

list::merge (STL/CLR)

順序指定された 2 つの制御シーケンスをマージします。

構文

void merge(list<Value>% right);
template<typename Pred2>
    void merge(list<Value>% right, Pred2 pred);

パラメーター

pred
要素ペアの比較子。

right
マージするコンテナー。

解説

最初のメンバー関数は、right によって制御されるシーケンスからすべての要素を削除し、それらを被制御シーケンスに挿入します。 どちらのシーケンスも、事前に operator< によって並べ替えられている必要があります。つまり、どちらのシーケンスでも、前に進んでいくときに要素の値が減少しないようにする必要があります。 生成されるシーケンスも、operator< によって並べ替えられます。 このメンバー関数を使うと、値が増加していく 2 つのシーケンスをマージして、同じく値が増加していくシーケンスを生成することができます。

2 番目のメンバー関数は最初のものと同じように動作しますが、シーケンスが pred によって並べ替えられる点が異なります。pred(X, Y) は、シーケンス内で Y に続くすべての要素 X に対して false である必要があります。 これを使うと、指定した述語関数またはデリゲートによって並べ替えられた 2 つのシーケンスをマージできます。

どちらの関数でも安定したマージが実行されます。元のいずれの被制御シーケンス内の要素ペアも、生成される被制御シーケンス内で反転することはありません。 また、生成される被制御シーケンス内の要素ペア XY の順序が等しい場合 (!(X < Y) && !(X < Y))、元の被制御シーケンスの要素が、right によって制御されるシーケンスの要素の前に置かれます。

// cliext_list_merge.cpp
// compile with: /clr
#include <cliext/list>

typedef cliext::list<wchar_t> Mylist;
int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'c');
    c1.push_back(L'e');

    // display initial contents " a c e"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    cliext::list<wchar_t> c2;
    c2.push_back(L'b');
    c2.push_back(L'd');
    c2.push_back(L'f');

    // display initial contents " b d f"
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // merge and display
    cliext::list<wchar_t> c3(c1);
    c3.merge(c2);
    for each (wchar_t elem in c3)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    System::Console::WriteLine("c2.size() = {0}", c2.size());

    // sort descending, merge descending, and redisplay
    c1.sort(cliext::greater<wchar_t>());
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    c3.sort(cliext::greater<wchar_t>());
    for each (wchar_t elem in c3)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    c3.merge(c1, cliext::greater<wchar_t>());
    for each (wchar_t elem in c3)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    System::Console::WriteLine("c1.size() = {0}", c1.size());
    return (0);
    }
a c e
b d f
a b c d e f
c2.size() = 0
e c a
f e d c b a
f e e d c c b a a
c1.size() = 0

list::operator= (STL/CLR)

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

構文

list<Value>% operator=(list<Value>% right);

パラメーター

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

解説

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

// cliext_list_operator_as.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign to a new container
    cliext::list<wchar_t> c2;
    c2 = c1;
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
a b c

list::pop_back (STL/CLR)

最後の要素を削除します。

構文

void pop_back();

解説

このメンバー関数は、被制御シーケンス (これは空でない必要があります) の最後の要素を削除します。 これは、リストを後ろの 1 つの要素分短くするために使用します。

// cliext_list_pop_back.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // pop an element and redisplay
    c1.pop_back();
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
a b

list::pop_front (STL/CLR)

最初の要素を削除します。

構文

void pop_front();

解説

このメンバー関数は、被制御シーケンスの最初の要素を削除します。これを空にすることはできません。 これは、リストを前の 1 つの要素分短くするために使用します。

// cliext_list_pop_front.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // pop an element and redisplay
    c1.pop_front();
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
b c

list::push_back (STL/CLR)

新規に末尾の要素を追加します。

構文

void push_back(value_type val);

解説

このメンバー関数は、被制御シーケンスの末尾に値 val を持つ要素を挿入します。 これは、リストに別の要素を追加するために使用します。

// cliext_list_push_back.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c

list::push_front (STL/CLR)

新しい最初の要素を追加します。

構文

void push_front(value_type val);

解説

このメンバー関数は、被制御シーケンスの先頭に値 val を持つ要素を挿入します。 これは、リストの前に別の要素を追加するために使用します。

// cliext_list_push_front.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_front(L'a');
    c1.push_front(L'b');
    c1.push_front(L'c');

    // display contents " c b a"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
c b a

list::rbegin (STL/CLR)

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

構文

reverse_iterator rbegin();

解説

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

// cliext_list_rbegin.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // inspect first two items in reversed sequence
    cliext::list<wchar_t>::reverse_iterator rit = c1.rbegin();
    System::Console::WriteLine("*rbegin() = {0}", *rit);
    System::Console::WriteLine("*++rbegin() = {0}", *++rit);

    // alter first two items and reinspect
    *--rit = L'x';
    *++rit = L'y';
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
*rbegin() = c
*++rbegin() = b
a y x

list::reference (STL/CLR)

要素への参照の型です。

構文

typedef value_type% reference;

解説

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

// cliext_list_reference.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    cliext::list<wchar_t>::iterator it = c1.begin();
    for (; it != c1.end(); ++it)
        {   // get a reference to an element
        cliext::list<wchar_t>::reference ref = *it;
        System::Console::Write("{0} ", ref);
        }
    System::Console::WriteLine();

    // modify contents " a b c"
    for (it = c1.begin(); it != c1.end(); ++it)
        {   // get a reference to an element
        cliext::list<wchar_t>::reference ref = *it;

        ref += (wchar_t)(L'A' - L'a');
        System::Console::Write("{0} ", ref);
        }
    System::Console::WriteLine();
    return (0);
    }
a b c
A B C

list::remove (STL/CLR)

指定した値を持つ要素を削除します。

構文

void remove(value_type val);

パラメーター

val
削除する要素の値。

解説

このメンバー関数は、((System::Object^)val)->Equals((System::Object^)x) が true である被制御シーケンス内の要素を削除します (存在する場合)。 これを使って、指定した値を持つ任意の要素を消去できます。

// cliext_list_remove.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // fail to remove and redisplay
    c1.remove(L'A');
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // remove and redisplay
    c1.remove(L'b');
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
a b c
a c

list::remove_if (STL/CLR)

指定したテストに合格した要素を削除します。

構文

template<typename Pred1>
    void remove_if(Pred1 pred);

パラメーター

pred
削除する要素のためのテスト。

解説

このメンバー関数は、被制御シーケンスから、pred(X) が true であるすべての要素 X を削除 (消去) します。 これを使って、関数またはデリゲートとして指定した条件を満たすすべての要素を削除できます。

// cliext_list_remove_if.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'b');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b b b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // fail to remove and redisplay
    c1.remove_if(cliext::binder2nd<cliext::equal_to<wchar_t> >(
        cliext::equal_to<wchar_t>(), L'd'));
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // remove and redisplay
    c1.remove_if(cliext::binder2nd<cliext::not_equal_to<wchar_t> >(
        cliext::not_equal_to<wchar_t>(), L'b'));
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b b b c
a b b b c
b b b

list::rend (STL/CLR)

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

構文

reverse_iterator rend();

解説

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

// cliext_list_rend.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // inspect first two items
    cliext::list<wchar_t>::reverse_iterator rit = c1.rend();
    --rit;
    System::Console::WriteLine("*-- --rend() = {0}", *--rit);
    System::Console::WriteLine("*--rend() = {0}", *++rit);

    // alter first two items and reinspect
    *--rit = L'x';
    *++rit = L'y';
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
*-- --rend() = b
*--rend() = a
y x c

list::resize (STL/CLR)

要素の数を変更します。

構文

void resize(size_type new_size);
void resize(size_type new_size, value_type val);

パラメーター

new_size
被制御シーケンスの新しいサイズ。

val
埋め込み要素の値。

解説

メンバー関数は両方とも、list::size (STL/CLR)() がそれ以降 new_size を確実に返すようにします。 被制御シーケンスを長くする必要がある場合、最初のメンバー関数では値 value_type() で要素を追加し、2 番目のメンバー関数では値 val で要素を追加します。 被制御シーケンスを短くするために、両方のメンバー関数は、最後の要素を list::size (STL/CLR)() -new_size 回効果的に消去します。 これを使用して、現在の被制御シーケンスをトリミングまたはパディングすることでシーケンスのサイズを確実に new_size にします。

// cliext_list_resize.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
// construct an empty container and pad with default values
    cliext::list<wchar_t> c1;
    System::Console::WriteLine("size() = {0}", c1.size());
    c1.resize(4);
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", (int)elem);
    System::Console::WriteLine();

    // resize to empty
    c1.resize(0);
    System::Console::WriteLine("size() = {0}", c1.size());

    // resize and pad
    c1.resize(5, L'x');
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
size() = 0
0 0 0 0
size() = 0
x x x x x

list::reverse (STL/CLR)

被制御シーケンスを反転させます。

構文

void reverse();

解説

このメンバー関数は、被制御シーケンス内のすべての要素の順序を反転します。 これを使って、要素のリストを反転できます。

// cliext_list_reverse.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // reverse and redisplay
    c1.reverse();
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
c b a

list::reverse_iterator (STL/CLR)

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

構文

typedef T3 reverse_iterator;

解説

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

// cliext_list_reverse_iterator.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c" reversed
    cliext::list<wchar_t>::reverse_iterator rit = c1.rbegin();
    for (; rit != c1.rend(); ++rit)
        System::Console::Write("{0} ", *rit);
    System::Console::WriteLine();

    // alter first element and redisplay
    rit = c1.rbegin();
    *rit = L'x';
    for (; rit != c1.rend(); ++rit)
        System::Console::Write("{0} ", *rit);
    System::Console::WriteLine();
    return (0);
    }
c b a
x b a

list::size (STL/CLR)

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

構文

size_type size();

解説

このメンバー関数は、被制御シーケンスの長さを返します。 被制御シーケンス内の現在の要素の数を特定する場合に使います。 シーケンスのサイズが 0 以外かどうかだけを確認する場合は、「list::empty (STL/CLR)()」を参照してください。

// cliext_list_size.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    System::Console::WriteLine("size() = {0} starting with 3", c1.size());

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

    // add elements and clear again
    c1.push_back(L'a');
    c1.push_back(L'b');
    System::Console::WriteLine("size() = {0} after adding 2", c1.size());
    return (0);
    }
a b c
size() = 3 starting with 3
size() = 0 after clearing
size() = 2 after adding 2

list::size_type (STL/CLR)

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

構文

typedef int size_type;

解説

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

// cliext_list_size_type.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // compute positive difference
    cliext::list<wchar_t>::size_type diff = 0;
    for (cliext::list<wchar_t>::iterator it = c1.begin();
        it != c1.end(); ++it)
        ++diff;
    System::Console::WriteLine("end()-begin() = {0}", diff);
    return (0);
    }
a b c
end()-begin() = 3

list::sort (STL/CLR)

制御されたシーケンスを並べ替えます。

構文

void sort();
template<typename Pred2>
    void sort(Pred2 pred);

パラメーター

pred
要素ペアの比較子。

解説

1 つ目のメンバー関数は、被制御シーケンス内の要素を operator< によって並べ替えます。つまり、シーケンス内を前に進んでいっても要素の値が減少しないようにようにします。 このメンバー関数を使って、シーケンスを昇順に並べ替えることができます。

2 番目のメンバー関数は最初のものと同じように動作しますが、シーケンスが pred によって並べ替えられる点が異なります。pred(X, Y) は、生成されるシーケンス内で Y に続くすべての要素 X に対して false になります。 これを使って、述語関数またはデリゲートによって指定する順序でシーケンスを並べ替えることができます。

どちらの関数でも安定した並べ替えが実行されます。元の被制御シーケンス内の要素ペアが、生成される被制御シーケンス内で反転することはありません。

// cliext_list_sort.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // sort descending and redisplay
    c1.sort(cliext::greater<wchar_t>());
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // sort ascending and redisplay
    c1.sort();
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
c b a
a b c

list::splice (STL/CLR)

ノード間のリンクを再びつなぎ合わせます。

構文

void splice(iterator where, list<Value>% right);
void splice(iterator where, list<Value>% right,
    iterator first);
void splice(iterator where, list<Value>% right,
    iterator first, iterator last);

パラメーター

first
スプライスする範囲の先頭。

last
スプライスする範囲の末尾。

right
スプライスする元のコンテナー。

where
その前にスプライスするコンテナー内の場所。

解説

1 つ目のメンバー関数は、right によって制御されるシーケンスを、where によって指し示される被制御シーケンス内の要素の前に挿入します。 また、right からすべての要素を削除します。 (%right 等しくない this必要があります。)これを使用して、1 つのリストのすべてを別のリストにスプライスします。

2 番目のメンバー関数は、right によって制御されるシーケンス内の first によって指し示される要素を削除し、それを where によって指し示される被制御シーケンス内の要素の前に挿入します。 (変更が発生しない場合wherewhere==||first== ++first)。これを使用して、1 つのリストの 1 つの要素を別のリストにスプライスします。

3 番目のメンバー関数は、right によって制御されるシーケンスの [first, last) によって指定されるサブ範囲を、where によって指し示される被制御シーケンス内の要素の前に挿入します。 また、right によって制御されるシーケンスから元のサブ範囲も削除します。 (right == this の場合、範囲 [first, last) に where によって指し示される要素を含めることはできません。) これを使って、0 個以上の要素を持つサブシーケンスを 1 つのリストから別のリストにスプライスできます。

// cliext_list_splice.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // splice to a new list
    cliext::list<wchar_t> c2;
    c2.splice(c2.begin(), c1);
    System::Console::WriteLine("c1.size() = {0}", c1.size());
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // return one element
    c1.splice(c1.end(), c2, c2.begin());
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // return remaining elements
    c1.splice(c1.begin(), c2, c2.begin(), c2.end());
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    System::Console::WriteLine("c2.size() = {0}", c2.size());
    return (0);
    }
a b c
c1.size() = 0
a b c
a
b c
b c a
c2.size() = 0

list::swap (STL/CLR)

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

構文

void swap(list<Value>% right);

パラメーター

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

解説

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

// cliext_list_swap.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct another container with repetition of values
    cliext::list<wchar_t> c2(5, L'x');
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // swap and redisplay
    c1.swap(c2);
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
x x x x x
x x x x x
a b c

list::to_array (STL/CLR)

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

構文

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

解説

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

// cliext_list_to_array.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

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

    c1.push_back(L'd');
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // display the earlier array copy
    for each (wchar_t elem in a1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c d
a b c

list::unique (STL/CLR)

指定されたテストに合格した隣接する要素を削除します。

構文

void unique();
template<typename Pred2>
    void unique(Pred2 pred);

パラメーター

pred
要素ペアの比較子。

解説

最初のメンバー関数は、直前の要素に一致するすべての要素を被制御シーケンスから削除 (消去) します。要素 X が要素 Y よりも前にあり、X == Y である場合、メンバー関数は Y を削除します。 これを使って、隣接する要素が等しいすべてのサブシーケンスを 1 つのコピーを除いてすべて削除できます。 被制御シーケンスが順序付けされている場合 (たとえば list::sort (STL/CLR)() を呼び出して)、メンバー関数は一意の値を持つ要素のみを残すことに注意してください。 (ターミナル メソッドという名前なのはそのためです)。

2 番目のメンバー関数は最初のメンバー関数と同じように動作しますが、pred(X, Y) である要素 X の後に続く各要素 Y を削除する点が異なります。 これを使って、隣接する要素が指定した述語関数またはデリゲートを満たすすべてのサブシーケンスを、1 つのコピーを除いてすべて削除できます。 被制御シーケンスが順序付けされている場合 (たとえば sort(pred) を呼び出して)、メンバー関数は他の要素と等しい順序付けを持たない要素のみを残すことに注意してください。

// cliext_list_unique.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // display contents after unique
    cliext::list<wchar_t> c2(c1);
    c2.unique();
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // display contents after unique(not_equal_to)
    c2 = c1;
    c2.unique(cliext::not_equal_to<wchar_t>());
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a a b c
a b c
a a

list::value_type (STL/CLR)

要素の型。

構文

typedef Value value_type;

解説

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

// cliext_list_value_type.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c" using value_type
    for (cliext::list<wchar_t>::iterator it = c1.begin();
        it != c1.end(); ++it)
        {   // store element in value_type object
        cliext::list<wchar_t>::value_type val = *it;

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

operator!= (list) (STL/CLR)

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

構文

template<typename Value>
    bool operator!=(list<Value>% left,
        list<Value>% right);

パラメーター

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

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

解説

この演算子関数は、!(left == right) を返します。 2 つのリストを要素ごとに比較する際、leftright と同じ順序付けでないかどうかをテストする場合に使います。

// cliext_list_operator_ne.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign to a new container
    cliext::list<wchar_t> c2;
    c2.push_back(L'a');
    c2.push_back(L'b');
    c2.push_back(L'd');

    // display contents " a b d"
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    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 b c
a b d
[a b c] != [a b c] is False
[a b c] != [a b d] is True

operator< (list) (STL/CLR)

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

構文

template<typename Value>
    bool operator<(list<Value>% left,
        list<Value>% right);

パラメーター

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

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

解説

この演算子関数は、!(right[i] < left[i]) の最小の位置である i について、left[i] < right[i] も true である場合に true を返します。 それ以外の場合は、left->size() < right->size() を返します。2 つのリストを要素ごとに比較する際、leftright より前に順序づけされているかどうかをテストする場合に使います。

// cliext_list_operator_lt.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign to a new container
    cliext::list<wchar_t> c2;
    c2.push_back(L'a');
    c2.push_back(L'b');
    c2.push_back(L'd');

    // display contents " a b d"
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    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 b c
a b d
[a b c] < [a b c] is False
[a b c] < [a b d] is True

operator<= (list) (STL/CLR)

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

構文

template<typename Value>
    bool operator<=(list<Value>% left,
        list<Value>% right);

パラメーター

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

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

解説

この演算子関数は、!(right < left) を返します。 2 つのリストを要素ごとに比較する際、leftright より後に順序づけされていないかどうかをテストする場合に使います。

// cliext_list_operator_le.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign to a new container
    cliext::list<wchar_t> c2;
    c2.push_back(L'a');
    c2.push_back(L'b');
    c2.push_back(L'd');

    // display contents " a b d"
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    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 b c
a b d
[a b c] <= [a b c] is True
[a b d] <= [a b c] is False

operator== (list) (STL/CLR)

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

構文

template<typename Value>
    bool operator==(list<Value>% left,
        list<Value>% right);

パラメーター

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

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

解説

この演算子関数が true を返すのは、leftright によって制御されるシーケンスの長さが同じで、それぞれの位置 i について left[i] ==right[i] の場合のみです。 2 つのリストを要素ごとに比較する際、leftright と同じ順序付けであるかどうかをテストする場合に使います。

// cliext_list_operator_eq.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign to a new container
    cliext::list<wchar_t> c2;
    c2.push_back(L'a');
    c2.push_back(L'b');
    c2.push_back(L'd');

    // display contents " a b d"
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    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 b c
a b d
[a b c] == [a b c] is True
[a b c] == [a b d] is False

operator> (list) (STL/CLR)

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

構文

template<typename Value>
    bool operator>(list<Value>% left,
        list<Value>% right);

パラメーター

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

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

解説

この演算子関数は、right<left を返します。 2 つのリストを要素ごとに比較する際、leftright より後に順序づけされているかどうかをテストする場合に使います。

// cliext_list_operator_gt.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign to a new container
    cliext::list<wchar_t> c2;
    c2.push_back(L'a');
    c2.push_back(L'b');
    c2.push_back(L'd');

    // display contents " a b d"
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    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 b c
a b d
[a b c] > [a b c] is False
[a b d] > [a b c] is True

operator>= (list) (STL/CLR)

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

構文

template<typename Value>
    bool operator>=(list<Value>% left,
        list<Value>% right);

パラメーター

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

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

解説

この演算子関数は、!(left<right) を返します。 2 つのリストを要素ごとに比較する際、leftright より前に順序づけされていないかどうかをテストする場合に使います。

// cliext_list_operator_ge.cpp
// compile with: /clr
#include <cliext/list>

int main()
    {
    cliext::list<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign to a new container
    cliext::list<wchar_t> c2;
    c2.push_back(L'a');
    c2.push_back(L'b');
    c2.push_back(L'd');

    // display contents " a b d"
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    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 b c
a b d
[a b c] >= [a b c] is True
[a b c] >= [a b d] is False