<cliext/utility> (STL/CLR)

STL/CLR ヘッダー <cliext/utility> を含め、クラス テンプレート pair といくつかのサポート関数テンプレートを定義します。

構文

#include <cliext/utility>

必要条件

ヘッダー:<cliext/utility>

名前空間cliext:

宣言

クラス 説明
pair 要素のペアをラップします。
Operator 説明
operator== (ペア) pair 等しい比較。
operator!= (ペア) pair 等しくない比較。
operator< (ペア) pair 比較より小さい。
operator<= (ペア) pair より小さいか等しい比較。
operator> (ペア) pair 比較より大きい値を指定します。
operator>= (ペア) pair より大きいか等しい比較。
機能 説明
make_pair 値のペアから pair を作成します。

pair

値のペアをラップするオブジェクトを記述するテンプレート クラス。

構文

template<typename Value1,
    typename Value2>
    ref class pair;

パラメーター

Value1
最初にラップされた値の型。

Value2
2 番目にラップされた値の型。

メンバー

型定義 説明
pair::first_type 最初にラップされた値の型。
pair::second_type 2 番目にラップされた値の型。
Member オブジェクト 説明
pair::first 最初に格納された値。
pair::second 2 番目に格納された値。
メンバー関数 説明
pair::pair pair オブジェクトを構築します。
pair::swap 2 つの pair オブジェクトのコンテンツを交換します。
Operator 説明
pair::operator= 格納されている値のペアを置き換えます。

解説

オブジェクトには、値のペアが格納されます。 このテンプレート クラスを使用して、2 つの値を 1 つのオブジェクトに結合します。 また、(ここで説明する) オブジェクト cliext::pair にはマネージド型のみが格納されます。アンマネージド型のペアを格納するには、<utility> で宣言された std::pair を使用します。

pair::first

最初にラップされた値。

構文

Value1 first;

解説

オブジェクトには、最初にラップされた値が格納されます。

// cliext_pair_first.cpp
// compile with: /clr
#include <cliext/utility>

int main()
    {
    cliext::pair<wchar_t, int> c1(L'x', 3);
    System::Console::WriteLine("[{0}, {1}]", c1.first, c1.second);

    cliext::pair<wchar_t, int>::first_type first_val = c1.first;
    cliext::pair<wchar_t, int>::second_type second_val = c1.second;
    System::Console::WriteLine("[{0}, {1}]", first_val, second_val);
    return (0);
    }
[x, 3]

pair::first_type

最初にラップされた値の型。

構文

typedef Value1 first_type;

解説

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

// cliext_pair_first_type.cpp
// compile with: /clr
#include <cliext/utility>

int main()
    {
    cliext::pair<wchar_t, int> c1(L'x', 3);
    System::Console::WriteLine("[{0}, {1}]", c1.first, c1.second);

    cliext::pair<wchar_t, int>::first_type first_val = c1.first;
    cliext::pair<wchar_t, int>::second_type second_val = c1.second;
    System::Console::WriteLine("[{0}, {1}]", first_val, second_val);
    return (0);
    }
[x, 3]

pair::operator=

格納されている値のペアを置き換えます。

構文

pair<Value1, Value2>% operator=(pair<Value1, Value2>% right);

パラメーター

right
pair を選択してコピーします。

解説

メンバー演算子は、オブジェクトにコピー right し、次に返します *this。 これを使用して、格納されている値のペアを格納されている値のペアのコピーに right置き換えます。

// cliext_pair_operator_as.cpp
// compile with: /clr
#include <cliext/utility>

int main()
    {
    cliext::pair<wchar_t, int> c1(L'x', 3);
    System::Console::WriteLine("[{0}, {1}]", c1.first, c1.second);

// assign to a new pair
    cliext::pair<wchar_t, int> c2;
    c2 = c1;
    System::Console::WriteLine("[{0}, {1}]", c2.first, c2.second);
    return (0);
    }
[x, 3]
[x, 3]

pair::pair

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

構文

pair();
pair(pair<Coll>% right);
pair(pair<Coll>^ right);
pair(Value1 val1, Value2 val2);

パラメーター

right
pair を選択して保存します。

val1
格納する最初の値。

val2
格納する 2 番目の値。

解説

コンストラクター:

pair();

既定の構築された値を使用して、格納されているペアを初期化します。

コンストラクター:

pair(pair<Value1, Value2>% right);

を使用して、格納されているペアを right.first 初期化します right.second

pair(pair<Value1, Value2>^ right);

を使用して、格納されているペアを right->first 初期化します right->second

コンストラクター:

pair(Value1 val1, Value2 val2);

を使用して、格納されているペアを val1 初期化します val2

// cliext_pair_construct.cpp
// compile with: /clr
#include <cliext/utility>

int main()
    {
// construct an empty container
    cliext::pair<wchar_t, int> c1;
    System::Console::WriteLine("[{0}, {1}]",
        c1.first == L'\0' ? "\\0" : "??", c1.second);

// construct with a pair of values
    cliext::pair<wchar_t, int> c2(L'x', 3);
    System::Console::WriteLine("[{0}, {1}]", c2.first, c2.second);

// construct by copying another pair
    cliext::pair<wchar_t, int> c3(c2);
    System::Console::WriteLine("[{0}, {1}]", c3.first, c3.second);

// construct by copying a pair handle
    cliext::pair<wchar_t, int> c4(%c3);
    System::Console::WriteLine("[{0}, {1}]", c4.first, c4.second);

    return (0);
    }
[\0, 0]
[x, 3]
[x, 3]
[x, 3]

pair::second

2 番目にラップされた値。

構文

Value2 second;

解説

オブジェクトには、2 番目にラップされた値が格納されます。

// cliext_pair_second.cpp
// compile with: /clr
#include <cliext/utility>

int main()
    {
    cliext::pair<wchar_t, int> c1(L'x', 3);
    System::Console::WriteLine("[{0}, {1}]", c1.first, c1.second);

    cliext::pair<wchar_t, int>::first_type first_val = c1.first;
    cliext::pair<wchar_t, int>::second_type second_val = c1.second;
    System::Console::WriteLine("[{0}, {1}]", first_val, second_val);
    return (0);
    }
[x, 3]

pair::second_type

2 番目にラップされた値の型。

構文

typedef Value2 second_type;

解説

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

// cliext_pair_second_type.cpp
// compile with: /clr
#include <cliext/utility>

int main()
    {
    cliext::pair<wchar_t, int> c1(L'x', 3);
    System::Console::WriteLine("[{0}, {1}]", c1.first, c1.second);

    cliext::pair<wchar_t, int>::first_type first_val = c1.first;
    cliext::pair<wchar_t, int>::second_type second_val = c1.second;
    System::Console::WriteLine("[{0}, {1}]", first_val, second_val);
    return (0);
    }
[x, 3]

pair::swap

2 つの pair オブジェクトのコンテンツを交換します。

構文

void swap(pair<Value1, Value2>% right);

パラメーター

right
pair を使用してコンテンツをスワップします。

解説

メンバー関数は、格納されている値のペアを入*thisrightれ替えます。

// cliext_pair_swap.cpp
// compile with: /clr
#include <cliext/adapter>
#include <cliext/deque>

typedef cliext::collection_adapter<
    System::Collections::ICollection> Mycoll;
int main()
    {
    cliext::deque<wchar_t> d1;
    d1.push_back(L'a');
    d1.push_back(L'b');
    d1.push_back(L'c');
    Mycoll c1(%d1);

// 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::deque<wchar_t> d2(5, L'x');
    Mycoll c2(%d2);
    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

make_pair

値のペアから pair を作成します。

構文

template<typename Value1,
    typename Value2>
    pair<Value1, Value2> make_pair(Value1 first, Value2 second);

パラメーター

Value1
最初にラップされた値の型。

Value2
2 番目にラップされた値の型。

first
ラップする最初の値。

second
ラップする 2 番目の値。

解説

関数テンプレートが返します pair<Value1, Value2>(first, second)。 値のペアから pair<Value1, Value2> オブジェクトを構築するために使用します。

// cliext_make_pair.cpp
// compile with: /clr
#include <cliext/utility>

int main()
    {
    cliext::pair<wchar_t, int> c1(L'x', 3);
    System::Console::WriteLine("[{0}, {1}]", c1.first, c1.second);

    c1 = cliext::make_pair(L'y', 4);
    System::Console::WriteLine("[{0}, {1}]", c1.first, c1.second);
    return (0);
    }
[x, 3]
[y, 4]

operator!= (ペア)

pair 等しくない比較。

構文

template<typename Value1,
    typename Value2>
    bool operator!=(pair<Value1, Value2>% left,
        pair<Value1, Value2>% right);

パラメーター

left
比較する左 pair

right
比較する権限 pair

解説

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

// cliext_pair_operator_ne.cpp
// compile with: /clr
#include <cliext/utility>

int main()
    {
    cliext::pair<wchar_t, int> c1(L'x', 3);
    System::Console::WriteLine("[{0}, {1}]", c1.first, c1.second);
    cliext::pair<wchar_t, int> c2(L'x', 4);
    System::Console::WriteLine("[{0}, {1}]", c2.first, c2.second);

    System::Console::WriteLine("[x 3] != [x 3] is {0}",
        c1 != c1);
    System::Console::WriteLine("[x 3] != [x 4] is {0}",
        c1 != c2);
    return (0);
    }
[x, 3]
[x, 4]
[x 3] != [x 3] is False
[x 3] != [x 4] is True

operator<

pair 比較より小さい。

構文

template<typename Value1,
    typename Value2>
    bool operator<(pair<Value1, Value2>% left,
        pair<Value1, Value2>% right);

パラメーター

left
比較する左 pair

right
比較する権限 pair

解説

この演算子関数は、left.first < right.first || !(right.first < left.first && left.second < right.second を返します。 これを使用して、2 つのpairオブジェクトが要素ごとに比較される前に順序付けrightされているかどうかをleftテストします。

// cliext_pair_operator_lt.cpp
// compile with: /clr
#include <cliext/utility>

int main()
    {
    cliext::pair<wchar_t, int> c1(L'x', 3);
    System::Console::WriteLine("[{0}, {1}]", c1.first, c1.second);
    cliext::pair<wchar_t, int> c2(L'x', 4);
    System::Console::WriteLine("[{0}, {1}]", c2.first, c2.second);

    System::Console::WriteLine("[x 3] < [x 3] is {0}",
        c1 < c1);
    System::Console::WriteLine("[x 3] < [x 4] is {0}",
        c1 < c2);
    return (0);
    }
[x, 3]
[x, 4]
[x 3] < [x 3] is False
[x 3] < [x 4] is True

operator<=

pair より小さいか等しい比較。

構文

template<typename Value1,
    typename Value2>
    bool operator<=(pair<Value1, Value2>% left,
        pair<Value1, Value2>% right);

パラメーター

left
比較する左 pair

right
比較する権限 pair

解説

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

// cliext_pair_operator_le.cpp
// compile with: /clr
#include <cliext/utility>

int main()
    {
    cliext::pair<wchar_t, int> c1(L'x', 3);
    System::Console::WriteLine("[{0}, {1}]", c1.first, c1.second);
    cliext::pair<wchar_t, int> c2(L'x', 4);
    System::Console::WriteLine("[{0}, {1}]", c2.first, c2.second);

    System::Console::WriteLine("[x 3] <= [x 3] is {0}",
        c1 <= c1);
    System::Console::WriteLine("[x 4] <= [x 3] is {0}",
        c2 <= c1);
    return (0);
    }
[x, 3]
[x, 4]
[x 3] <= [x 3] is True
[x 4] <= [x 3] is False

operator==

pair 等しい比較。

構文

template<typename Value1,
    typename Value2>
    bool operator==(pair<Value1, Value2>% left,
        pair<Value1, Value2>% right);

パラメーター

left
比較する左 pair

right
比較する権限 pair

解説

この演算子関数は、left.first == right.first && left.second == right.second を返します。 これを使用して、2 つのpairオブジェクトが要素ごとに比較される場合とright同じ順序になっているかどうかをleftテストします。

// cliext_pair_operator_eq.cpp
// compile with: /clr
#include <cliext/utility>

int main()
    {
    cliext::pair<wchar_t, int> c1(L'x', 3);
    System::Console::WriteLine("[{0}, {1}]", c1.first, c1.second);
    cliext::pair<wchar_t, int> c2(L'x', 4);
    System::Console::WriteLine("[{0}, {1}]", c2.first, c2.second);

    System::Console::WriteLine("[x 3] == [x 3] is {0}",
        c1 == c1);
    System::Console::WriteLine("[x 3] == [x 4] is {0}",
        c1 == c2);
    return (0);
    }
[x, 3]
[x, 4]
[x 3] == [x 3] is True
[x 3] == [x 4] is False

pair::operator>

pair 比較より大きい値を指定します。

構文

template<typename Value1,
    typename Value2>
    bool operator>(pair<Value1, Value2>% left,
        pair<Value1, Value2>% right);

パラメーター

left
比較する左 pair

right
比較する権限 pair

解説

この演算子関数は、right < left を返します。 これを使用して、2 つのpairオブジェクトが要素ごとに比較された後rightに並べ替えられるかどうかをleftテストします。

// cliext_pair_operator_gt.cpp
// compile with: /clr
#include <cliext/utility>

int main()
    {
    cliext::pair<wchar_t, int> c1(L'x', 3);
    System::Console::WriteLine("[{0}, {1}]", c1.first, c1.second);
    cliext::pair<wchar_t, int> c2(L'x', 4);
    System::Console::WriteLine("[{0}, {1}]", c2.first, c2.second);

    System::Console::WriteLine("[x 3] > [x 3] is {0}",
        c1 > c1);
    System::Console::WriteLine("[x 4] > [x 3] is {0}",
        c2 > c1);
    return (0);
    }
[x, 3]
[x, 4]
[x 3] > [x 3] is False
[x 4] > [x 3] is True

operator>=

pair より大きいか等しい比較。

構文

template<typename Value1,
    typename Value2>
    bool operator>=(pair<Value1, Value2>% left,
        pair<Value1, Value2>% right);

パラメーター

left
比較する左 pair

right
比較する権限 pair

解説

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

// cliext_pair_operator_ge.cpp
// compile with: /clr
#include <cliext/utility>

int main()
    {
    cliext::pair<wchar_t, int> c1(L'x', 3);
    System::Console::WriteLine("[{0}, {1}]", c1.first, c1.second);
    cliext::pair<wchar_t, int> c2(L'x', 4);
    System::Console::WriteLine("[{0}, {1}]", c2.first, c2.second);

    System::Console::WriteLine("[x 3] >= [x 3] is {0}",
        c1 >= c1);
    System::Console::WriteLine("[x 3] >= [x 4] is {0}",
        c1 >= c2);
    return (0);
    }
[x, 3]
[x, 4]
[x 3] >= [x 3] is True
[x 3] >= [x 4] is False