functional (STL/CLR)

STL/CLR ヘッダー <cliext/functional> を含め、関数型クラス テンプレートと関連するテンプレート デリゲートと関数を定義します。

構文

#include <functional>

必要条件

ヘッダー:<cliext/functional>

名前空間cliext:

宣言

代理人 説明
binary_delegate (STL/CLR) 2 つの引数を持つデリゲート。
binary_delegate_noreturn (STL/CLR) void を返す 2 引数のデリゲート。
unary_delegate (STL/CLR) 1 つの引数を持つデリゲート。
unary_delegate_noreturn (STL/CLR) void を返す 1 引数のデリゲート。
クラス 説明
binary_negate (STL/CLR) 2 引数のファンクターを否定するファンクター。
binder1st (STL/CLR) 1 番目の引数を 2 引数のファンクターにバインドするファンクター。
binder2nd (STL/CLR) 2 番目の引数を 2 引数のファンクターにバインドするファンクター。
divides (STL/CLR) 除算ファンクター。
equal_to (STL/CLR) 等しいかどうかを比較するファンクター。
greater (STL/CLR) より大きいかどうかを比較するファンクター。
greater_equal (STL/CLR) 以上かどうかを比較するファンクター。
less (STL/CLR) より小さいかどうかを比較するファンクター。
less_equal (STL/CLR) 以下かどうかを比較するファンクター。
logical_and (STL/CLR) 論理 AND ファンクター。
logical_not (STL/CLR) 論理 NOT ファンクター。
logical_or (STL/CLR) 論理 OR ファンクター。
minus (STL/CLR) 減算ファンクター。
modulus (STL/CLR) 剰余ファンクター。
multiplies (STL/CLR) 乗算ファンクター。
negate (STL/CLR) 引数を否定して返すファンクター。
not_equal_to (STL/CLR) 等しくないどうかを比較するファンクター。
plus (STL/CLR) 加算ファンクター。
unary_negate (STL/CLR) 1 引数のファンクターを否定するファンクター。
機能 説明
bind1st (STL/CLR) 引数とファンクターに対する binder1st を生成します。
bind2nd (STL/CLR) 引数とファンクターに対する binder2nd を生成します。
not1 (STL/CLR) ファンクターの unary_negate を生成します。
not2 (STL/CLR) ファンクターの binary_negate を生成します。

メンバー

binary_delegate (STL/CLR)

ジェネリック クラスは、2 引数デリゲートを記述します。 これを使用して、デリゲートの引数と戻り値の型を指定します。

構文

generic<typename Arg1,
    typename Arg2,
    typename Result>
    delegate Result binary_delegate(Arg1, Arg2);

パラメーター

Arg1
1 番目の引数の型。

Arg2
2 番目の引数の型。

Result
戻り値の型。

解説

ジェネリック デリゲートは、2 つの引数関数を記述します。

これらの関数テンプレートでは、次の手順を実行します。

binary_delegate<int, int, int> Fun1;

binary_delegate<int, int, int> Fun2;

この場合、型 Fun1Fun2 はシノニムです。

delegate int Fun1(int, int);

delegate int Fun2(int, int);

これらは同じ型ではありません。

// cliext_binary_delegate.cpp
// compile with: /clr
#include <cliext/functional>

bool key_compare(wchar_t left, wchar_t right)
    {
    return (left < right);
    }

typedef cliext::binary_delegate<wchar_t, wchar_t, bool> Mydelegate;
int main()
    {
    Mydelegate^ kcomp = gcnew Mydelegate(&key_compare);

    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();
    return (0);
    }
compare(L'a', L'a') = False
compare(L'a', L'b') = True
compare(L'b', L'a') = False

binary_delegate_noreturn (STL/CLR)

ジェネリック クラスは、... を返す 2 引数デリゲートを記述します void。 これを使用して、デリゲートの引数を指定します。

構文

generic<typename Arg1,
    typename Arg2>
    delegate void binary_delegate(Arg1, Arg2);

パラメーター

Arg1
1 番目の引数の型。

Arg2
2 番目の引数の型。

解説

ジェネリック デリゲートは、... を返す 2 引数関数を記述します void

これらの関数テンプレートでは、次の手順を実行します。

binary_delegate_noreturn<int, int> Fun1;

binary_delegate_noreturn<int, int> Fun2;

この場合、型 Fun1Fun2 はシノニムです。

delegate void Fun1(int, int);

delegate void Fun2(int, int);

これらは同じ型ではありません。

// cliext_binary_delegate_noreturn.cpp
// compile with: /clr
#include <cliext/functional>

void key_compare(wchar_t left, wchar_t right)
    {
    System::Console::WriteLine("compare({0}, {1}) = {2}",
        left, right, left < right);
    }

typedef cliext::binary_delegate_noreturn<wchar_t, wchar_t> Mydelegate;
int main()
    {
    Mydelegate^ kcomp = gcnew Mydelegate(&key_compare);

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

binary_negate (STL/CLR)

このテンプレート クラスは、呼び出されると、格納されている 2 引数のファンクターの論理 NOT を返すファンクターを記述します。 これを使用して、関数オブジェクトの格納されているファンクターを指定します。

構文

template<typename Fun>
    ref class binary_negate
    { // wrap operator()
public:
    typedef Fun stored_function_type;
    typedef typename Fun::first_argument_type first_argument_type;
    typedef typename Fun::second_argument_type second_argument_type;
    typedef bool result_type;
    typedef Microsoft::VisualC::StlClr::BinaryDelegate<
        first_argument_type, second_argument_type, result_type>
        delegate_type;

    explicit binary_negate(Fun% functor);
    binary_negate(binary_negate<Arg>% right);

    result_type operator()(first_argument_type left,
        second_argument_type right);
    operator delegate_type^();
    };

パラメーター

Fun
格納されているファンクターの型。

メンバー関数

型の定義 説明
delegate_type 汎用デリゲートの型。
first_argument_type ファンクターの 1 番目の引数の型。
result_type ファンクターの結果の型。
second_argument_type ファンクターの 2 番目の引数の型。
stored_function_type ファンクターの型。
メンバー 説明
binary_negate ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^() ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、別の 2 引数のファンクターを格納する 2 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、格納されている 2 引数のファンクターの論理 NOT を返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_binary_negate.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(3);
    Myvector c2;
    c2.push_back(4);
    c2.push_back(4);
    Myvector c3(2, 0);

// display initial contents " 4 3" and " 4 4"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

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

// transform and display
    cliext::less<int> less_op;

    cliext::transform(c1.begin(), c1.begin() + 2,
        c2.begin(), c3.begin(),
        cliext::binary_negate<cliext::less<int> >(less_op));
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

// transform and display with function
    cliext::transform(c1.begin(), c1.begin() + 2,
        c2.begin(), c3.begin(), cliext::not2(less_op));
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 3
4 4
1 0
1 0

bind1st (STL/CLR)

引数とファンクターに対する binder1st を生成します。

構文

template<typename Fun,
    typename Arg>
    binder1st<Fun> bind1st(Fun% functor,
        Arg left);

テンプレート パラメーター

Arg
引数の型。

Fun
ファンクターの型。

関数パラメーター

functor
ラップするファンクター。

left
ラップする 1 番目の引数。

解説

関数テンプレートが返します binder1st<Fun>(functor, left)。 2 引数のファンクターとその 1 番目の引数を、2 番目の引数でそれを呼び出す 1 引数のファンクターにラップする便利な方法として、これを使用します。

// cliext_bind1st.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(3);
    Myvector c3(2, 0);

// display initial contents " 4 3"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

// transform and display
    cliext::minus<int> sub_op;
    cliext::binder1st<cliext::minus<int> > subfrom3(sub_op, 3);

    cliext::transform(c1.begin(), c1.begin() + 2, c3.begin(),
        subfrom3);
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

// transform and display with function
    cliext::transform(c1.begin(), c1.begin() + 2, c3.begin(),
        bind1st(sub_op, 3));
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 3
-1 0
-1 0

bind2nd (STL/CLR)

引数とファンクターに対する binder2nd を生成します。

構文

template<typename Fun,
    typename Arg>
    binder2nd<Fun> bind2nd(Fun% functor,
        Arg right);

テンプレート パラメーター

Arg
引数の型。

Fun
ファンクターの型。

関数パラメーター

functor
ラップするファンクター。

right
ラップする 2 番目の引数。

解説

関数テンプレートが返します binder2nd<Fun>(functor, right)。 2 引数のファンクターとその 2 番目の引数を、1 番目の引数でそれを呼び出す 1 引数のファンクターにラップする便利な方法として、これを使用します。

// cliext_bind2nd.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(3);
    Myvector c3(2, 0);

// display initial contents " 4 3"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

// transform and display
    cliext::minus<int> sub_op;
    cliext::binder2nd<cliext::minus<int> > sub4(sub_op, 4);

    cliext::transform(c1.begin(), c1.begin() + 2, c3.begin(),
        sub4);
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

// transform and display with function
    cliext::transform(c1.begin(), c1.begin() + 2, c3.begin(),
        bind2nd(sub_op, 4));
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 3
0 -1
0 -1

binder1st (STL/CLR)

このテンプレート クラスによって記述される 1 引数のファンクターは、呼び出されると、格納されている 1 番目の引数と指定された 2 番目の引数を使って呼び出される、格納されている 2 引数のファンクターを返します。 これを使用して、関数オブジェクトの格納されているファンクターを指定します。

構文

template<typename Fun>
    ref class binder1st
    { // wrap operator()
public:
    typedef Fun stored_function_type;
    typedef typename Fun::first_argument_type first_argument_type;
    typedef typename Fun::second_argument_type second_argument_type;
    typedef typename Fun:result_type result_type;
    typedef Microsoft::VisualC::StlClr::UnaryDelegate<
        second_argument_type, result_type>
        delegate_type;

    binder1st(Fun% functor, first_argument_type left);
    binder1st(binder1st<Arg>% right);

    result_type operator()(second_argument_type right);
    operator delegate_type^();
    };

パラメーター

Fun
格納されているファンクターの型。

メンバー関数

型の定義 説明
delegate_type 汎用デリゲートの型。
first_argument_type ファンクターの 1 番目の引数の型。
result_type ファンクターの結果の型。
second_argument_type ファンクターの 2 番目の引数の型。
stored_function_type ファンクターの型。
メンバー 説明
binder1st ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^() ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、2 引数のファンクターと 1 番目の引数を格納する 1 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、格納されている 1 番目の引数と指定された 2 番目の引数を使って格納されているファンクターを呼び出し、その結果を返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_binder1st.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(3);
    Myvector c3(2, 0);

// display initial contents " 4 3"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

// transform and display
    cliext::minus<int> sub_op;
    cliext::binder1st<cliext::minus<int> > subfrom3(sub_op, 3);

    cliext::transform(c1.begin(), c1.begin() + 2, c3.begin(),
        subfrom3);
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

// transform and display with function
    cliext::transform(c1.begin(), c1.begin() + 2, c3.begin(),
        bind1st(sub_op, 3));
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 3
-1 0
-1 0

binder2nd (STL/CLR)

このテンプレート クラスによって記述される 1 引数のファンクターは、呼び出されると、指定された 1 番目の引数と格納されている 2 番目の引数を使って呼び出される、格納されている 2 引数のファンクターを返します。 これを使用して、関数オブジェクトの格納されているファンクターを指定します。

構文

template<typename Fun>
    ref class binder2nd
    { // wrap operator()
public:
    typedef Fun stored_function_type;
    typedef typename Fun::first_argument_type first_argument_type;
    typedef typename Fun::second_argument_type second_argument_type;
    typedef typename Fun:result_type result_type;
    typedef Microsoft::VisualC::StlClr::UnaryDelegate<
        first_argument_type, result_type>
        delegate_type;

    binder2nd(Fun% functor, second_argument_type left);
    binder2nd(binder2nd<Arg>% right);

    result_type operator()(first_argument_type right);
    operator delegate_type^();
    };

パラメーター

Fun
格納されているファンクターの型。

メンバー関数

型の定義 説明
delegate_type 汎用デリゲートの型。
first_argument_type ファンクターの 1 番目の引数の型。
result_type ファンクターの結果の型。
second_argument_type ファンクターの 2 番目の引数の型。
stored_function_type ファンクターの型。
メンバー 説明
binder2nd ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^() ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、2 引数のファンクターと 2 番目の引数を格納する 1 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、指定された 1 番目の引数と格納されている 2 番目の引数を使って格納されているファンクターを呼び出し、その結果を返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_binder2nd.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(3);
    Myvector c3(2, 0);

// display initial contents " 4 3"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

// transform and display
    cliext::minus<int> sub_op;
    cliext::binder2nd<cliext::minus<int> > sub4(sub_op, 4);

    cliext::transform(c1.begin(), c1.begin() + 2, c3.begin(),
        sub4);
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

// transform and display with function
    cliext::transform(c1.begin(), c1.begin() + 2, c3.begin(),
        bind2nd(sub_op, 4));
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 3
0 -1
0 -1

divides (STL/CLR)

このテンプレート クラスによって記述されるファンクターは、呼び出されると、1 番目の引数を 2 番目の引数で除算して返します。 これを使用して、関数オブジェクトの引数の型を指定します。

構文

template<typename Arg>
    ref class divides
    { // wrap operator()
public:
    typedef Arg first_argument_type;
    typedef Arg second_argument_type;
    typedef Arg result_type;
    typedef Microsoft::VisualC::StlClr::BinaryDelegate<
        first_argument_type, second_argument_type, result_type>
        delegate_type;

    divides();
    divides(divides<Arg>% right);

    result_type operator()(first_argument_type left,
        second_argument_type right);
    operator delegate_type^();
    };

パラメーター

Arg
引数と戻り値の型。

メンバー関数

型の定義 説明
delegate_type 汎用デリゲートの型。
first_argument_type ファンクターの 1 番目の引数の型。
result_type ファンクターの結果の型。
second_argument_type ファンクターの 2 番目の引数の型。
メンバー 説明
divides ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^() ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、2 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、1 番目の引数を 2 番目の引数で除算して返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_divides.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(3);
    Myvector c2;
    c2.push_back(2);
    c2.push_back(1);
    Myvector c3(2, 0);

// display initial contents " 4 3" and " 2 1"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

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

// transform and display
    cliext::transform(c1.begin(), c1.begin() + 2,
        c2.begin(), c3.begin(), cliext::divides<int>());
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 3
2 1
2 3

equal_to (STL/CLR)

このテンプレート クラスによって記述されるファンクターは、呼び出されると、1 番目の引数が 2 番目と等しい場合にのみ true を返します。 これを使用して、関数オブジェクトの引数の型を指定します。

構文

template<typename Arg>
    ref class equal_to
    { // wrap operator()
public:
    typedef Arg first_argument_type;
    typedef Arg second_argument_type;
    typedef bool result_type;
    typedef Microsoft::VisualC::StlClr::BinaryDelegate<
        first_argument_type, second_argument_type, result_type>
        delegate_type;

    equal_to();
    equal_to(equal_to<Arg>% right);

    result_type operator()(first_argument_type left,
        second_argument_type right);
    operator delegate_type^();
    };

パラメーター

Arg
引数の型。

メンバー関数

型の定義 説明
delegate_type 汎用デリゲートの型。
first_argument_type ファンクターの 1 番目の引数の型。
result_type ファンクターの結果の型。
second_argument_type ファンクターの 2 番目の引数の型。
メンバー 説明
equal_to ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^() ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、2 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、1 番目の引数が 2 番目と等しい場合にのみ true を返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_equal_to.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(3);
    Myvector c2;
    c2.push_back(4);
    c2.push_back(4);
    Myvector c3(2, 0);

// display initial contents " 4 3" and " 4 4"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

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

// transform and display
    cliext::transform(c1.begin(), c1.begin() + 2,
        c2.begin(), c3.begin(), cliext::equal_to<int>());
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 3
4 4
1 0

greater (STL/CLR)

このテンプレート クラスによって記述されるファンクターは、呼び出されると、1 番目の引数が 2 番目より大きい場合にのみ true を返します。 これを使用して、関数オブジェクトの引数の型を指定します。

構文

template<typename Arg>
    ref class greater
    { // wrap operator()
public:
    typedef Arg first_argument_type;
    typedef Arg second_argument_type;
    typedef bool result_type;
    typedef Microsoft::VisualC::StlClr::BinaryDelegate<
        first_argument_type, second_argument_type, result_type>
        delegate_type;

    greater();
    greater(greater<Arg>% right);

    result_type operator()(first_argument_type left,
        second_argument_type right);
    operator delegate_type^();
    };

パラメーター

Arg
引数の型。

メンバー関数

型の定義 説明
delegate_type 汎用デリゲートの型。
first_argument_type ファンクターの 1 番目の引数の型。
result_type ファンクターの結果の型。
second_argument_type ファンクターの 2 番目の引数の型。
メンバー 説明
greater ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^ ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、2 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、1 番目の引数が 2 番目より大きい場合にのみ true を返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_greater.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(3);
    Myvector c2;
    c2.push_back(3);
    c2.push_back(3);
    Myvector c3(2, 0);

// display initial contents " 4 3" and " 3 3"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

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

// transform and display
    cliext::transform(c1.begin(), c1.begin() + 2,
        c2.begin(), c3.begin(), cliext::greater<int>());
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 3
3 3
1 0

greater_equal (STL/CLR)

このテンプレート クラスによって記述されるファンクターは、呼び出されると、1 番目の引数が 2 番目以上の場合にのみ true を返します。 これを使用して、関数オブジェクトの引数の型を指定します。

構文

template<typename Arg>
    ref class greater_equal
    { // wrap operator()
public:
    typedef Arg first_argument_type;
    typedef Arg second_argument_type;
    typedef bool result_type;
    typedef Microsoft::VisualC::StlClr::BinaryDelegate<
        first_argument_type, second_argument_type, result_type>
        delegate_type;

    greater_equal();
    greater_equal(greater_equal<Arg>% right);

    result_type operator()(first_argument_type left,
        second_argument_type right);
    operator delegate_type^();
    };

パラメーター

Arg
引数の型。

メンバー関数

型の定義 説明
delegate_type 汎用デリゲートの型。
first_argument_type ファンクターの 1 番目の引数の型。
result_type ファンクターの結果の型。
second_argument_type ファンクターの 2 番目の引数の型。
メンバー 説明
greater_equal ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^ ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、2 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、1 番目の引数が 2 番目以上の場合にのみ true を返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_greater_equal.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(3);
    Myvector c2;
    c2.push_back(4);
    c2.push_back(4);
    Myvector c3(2, 0);

// display initial contents " 4 3" and " 4 4"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

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

// transform and display
    cliext::transform(c1.begin(), c1.begin() + 2,
        c2.begin(), c3.begin(), cliext::greater_equal<int>());
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 3
4 4
1 0

less (STL/CLR)

このテンプレート クラスによって記述されるファンクターは、呼び出されると、1 番目の引数が 2 番目より小さい場合にのみ true を返します。 これを使用して、関数オブジェクトの引数の型を指定します。

構文

template<typename Arg>
    ref class less
    { // wrap operator()
public:
    typedef Arg first_argument_type;
    typedef Arg second_argument_type;
    typedef bool result_type;
    typedef Microsoft::VisualC::StlClr::BinaryDelegate<
        first_argument_type, second_argument_type, result_type>
        delegate_type;

    less();
    less(less<Arg>% right);

    result_type operator()(first_argument_type left,
        second_argument_type right);
    operator delegate_type^();
    };

パラメーター

Arg
引数の型。

メンバー関数

型の定義 説明
delegate_type 汎用デリゲートの型。
first_argument_type ファンクターの 1 番目の引数の型。
result_type ファンクターの結果の型。
second_argument_type ファンクターの 2 番目の引数の型。
メンバー 説明
less ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^ ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、2 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、1 番目の引数が 2 番目より小さい場合にのみ true を返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_less.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(3);
    Myvector c2;
    c2.push_back(4);
    c2.push_back(4);
    Myvector c3(2, 0);

// display initial contents " 4 3" and " 4 4"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

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

// transform and display
    cliext::transform(c1.begin(), c1.begin() + 2,
        c2.begin(), c3.begin(), cliext::less<int>());
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 3
4 4
0 1

less_equal (STL/CLR)

このテンプレート クラスによって記述されるファンクターは、呼び出されると、1 番目の引数が 2 番目以下の場合にのみ true を返します。 これを使用して、関数オブジェクトの引数の型を指定します。

構文

template<typename Arg>
    ref class less_equal
    { // wrap operator()
public:
    typedef Arg first_argument_type;
    typedef Arg second_argument_type;
    typedef bool result_type;
    typedef Microsoft::VisualC::StlClr::BinaryDelegate<
        first_argument_type, second_argument_type, result_type>
        delegate_type;

    less_equal();
    less_equal(less_equal<Arg>% right);

    result_type operator()(first_argument_type left,
        second_argument_type right);
    operator delegate_type^();
    };

パラメーター

Arg
引数の型。

メンバー関数

型の定義 説明
delegate_type 汎用デリゲートの型。
first_argument_type ファンクターの 1 番目の引数の型。
result_type ファンクターの結果の型。
second_argument_type ファンクターの 2 番目の引数の型。
メンバー 説明
less_equal ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^ ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、2 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、1 番目の引数が 2 番目以下の場合にのみ true を返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_less_equal.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(3);
    Myvector c2;
    c2.push_back(3);
    c2.push_back(3);
    Myvector c3(2, 0);

// display initial contents " 4 3" and " 3 3"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

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

// transform and display
    cliext::transform(c1.begin(), c1.begin() + 2,
        c2.begin(), c3.begin(), cliext::less_equal<int>());
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 3
3 3
0 1

logical_and (STL/CLR)

このテンプレート クラスによって記述されるファンクターは、呼び出されると、1 番目と 2 番目の引数が両方とも true と評価される場合にのみ true を返します。 これを使用して、関数オブジェクトの引数の型を指定します。

構文

template<typename Arg>
    ref class logical_and
    { // wrap operator()
public:
    typedef Arg first_argument_type;
    typedef Arg second_argument_type;
    typedef bool result_type;
    typedef Microsoft::VisualC::StlClr::BinaryDelegate<
        first_argument_type, second_argument_type, result_type>
        delegate_type;

    logical_and();
    logical_and(logical_and<Arg>% right);

    result_type operator()(first_argument_type left,
        second_argument_type right);
    operator delegate_type^();
    };

パラメーター

Arg
引数の型。

メンバー関数

型の定義 説明
delegate_type 汎用デリゲートの型。
first_argument_type ファンクターの 1 番目の引数の型。
result_type ファンクターの結果の型。
second_argument_type ファンクターの 2 番目の引数の型。
メンバー 説明
logical_and ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^ ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、2 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、1 番目と 2 番目の引数が両方とも true と評価される場合にのみ true を返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_logical_and.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(2);
    c1.push_back(0);
    Myvector c2;
    c2.push_back(3);
    c2.push_back(0);
    Myvector c3(2, 0);

// display initial contents " 1 0" and " 1 0"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

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

// transform and display
    cliext::transform(c1.begin(), c1.begin() + 2,
        c2.begin(), c3.begin(), cliext::logical_and<int>());
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
2 0
3 0
1 0

logical_not (STL/CLR)

このテンプレート クラスによって記述されるファンクターは、呼び出されると、その引数のいずれかが false と評価される場合にのみ true を返します。 これを使用して、関数オブジェクトの引数の型を指定します。

構文

template<typename Arg>
    ref class logical_not
    { // wrap operator()
public:
    typedef Arg argument_type;
    typedef bool result_type;
    typedef Microsoft::VisualC::StlClr::UnaryDelegate<
        argument_type, result_type>
        delegate_type;

    logical_not();
    logical_not(logical_not<Arg> %right);

    result_type operator()(argument_type left);
    operator delegate_type^();
    };

パラメーター

Arg
引数の型。

メンバー関数

型の定義 説明
argument_type ファンクターの引数の型。
delegate_type 汎用デリゲートの型。
result_type ファンクターの結果の型。
メンバー 説明
logical_not ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^ ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、1 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、引数が false と評価される場合にのみ true を返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_logical_not.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(0);
    Myvector c3(2, 0);

// display initial contents " 4 0"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

// transform and display
    cliext::transform(c1.begin(), c1.begin() + 2,
        c3.begin(), cliext::logical_not<int>());
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 0
0 1

logical_or (STL/CLR)

このテンプレート クラスによって記述されるファンクターは、呼び出されると、1 番目または 2 番目の引数のいずれかが true と評価される場合にのみ true を返します。 これを使用して、関数オブジェクトの引数の型を指定します。

構文

template<typename Arg>
    ref class logical_or
    { // wrap operator()
public:
    typedef Arg first_argument_type;
    typedef Arg second_argument_type;
    typedef bool result_type;
    typedef Microsoft::VisualC::StlClr::BinaryDelegate<
        first_argument_type, second_argument_type, result_type>
        delegate_type;

    logical_or();
    logical_or(logical_or<Arg>% right);

    result_type operator()(first_argument_type left,
        second_argument_type right);
    operator delegate_type^();
    };

パラメーター

Arg
引数の型。

メンバー関数

型の定義 説明
delegate_type 汎用デリゲートの型。
first_argument_type ファンクターの 1 番目の引数の型。
result_type ファンクターの結果の型。
second_argument_type ファンクターの 2 番目の引数の型。
メンバー 説明
logical_or ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^ ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、2 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、1 番目または 2 番目の引数のいずれかが true と評価される場合にのみ true を返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_logical_or.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(2);
    c1.push_back(0);
    Myvector c2;
    c2.push_back(0);
    c2.push_back(0);
    Myvector c3(2, 0);

// display initial contents " 2 0" and " 0 0"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

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

// transform and display
    cliext::transform(c1.begin(), c1.begin() + 2,
        c2.begin(), c3.begin(), cliext::logical_or<int>());
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
2 0
0 0
1 0

minus (STL/CLR)

このテンプレート クラスによって記述されるファンクターは、呼び出されると、1 番目の引数から 2 番目の引数を減算して返します。 これを使用して、関数オブジェクトの引数の型を指定します。

構文

template<typename Arg>
    ref class minus
    { // wrap operator()
public:
    typedef Arg first_argument_type;
    typedef Arg second_argument_type;
    typedef Arg result_type;
    typedef Microsoft::VisualC::StlClr::BinaryDelegate<
        first_argument_type, second_argument_type, result_type>
        delegate_type;

    minus();
    minus(minus<Arg>% right);

    result_type operator()(first_argument_type left,
        second_argument_type right);
    operator delegate_type^();
    };

パラメーター

Arg
引数と戻り値の型。

メンバー関数

型の定義 説明
delegate_type 汎用デリゲートの型。
first_argument_type ファンクターの 1 番目の引数の型。
result_type ファンクターの結果の型。
second_argument_type ファンクターの 2 番目の引数の型。
メンバー 説明
minus ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^ ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、2 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、1 番目の引数から 2 番目の引数を減算して返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_minus.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(3);
    Myvector c2;
    c2.push_back(2);
    c2.push_back(1);
    Myvector c3(2, 0);

// display initial contents " 4 3" and " 2 1"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

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

// transform and display
    cliext::transform(c1.begin(), c1.begin() + 2,
        c2.begin(), c3.begin(), cliext::minus<int>());
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 3
2 1
2 2

modulus (STL/CLR)

このテンプレート クラスによって記述されるファンクターは、呼び出されると、1 番目の引数に対する 2 番目の剰余を返します。 これを使用して、関数オブジェクトの引数の型を指定します。

構文

template<typename Arg>
    ref class modulus
    { // wrap operator()
public:
    typedef Arg first_argument_type;
    typedef Arg second_argument_type;
    typedef Arg result_type;
    typedef Microsoft::VisualC::StlClr::BinaryDelegate<
        first_argument_type, second_argument_type, result_type>
        delegate_type;

    modulus();
    modulus(modulus<Arg>% right);

    result_type operator()(first_argument_type left,
        second_argument_type right);
    operator delegate_type^();
    };

パラメーター

Arg
引数と戻り値の型。

メンバー関数

型の定義 説明
delegate_type 汎用デリゲートの型。
first_argument_type ファンクターの 1 番目の引数の型。
result_type ファンクターの結果の型。
second_argument_type ファンクターの 2 番目の引数の型。
メンバー 説明
modulus ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^ ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、2 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、1 番目の引数に対する 2 番目の剰余を返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_modulus.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(2);
    Myvector c2;
    c2.push_back(3);
    c2.push_back(1);
    Myvector c3(2, 0);

// display initial contents " 4 2" and " 3 1"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

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

// transform and display
    cliext::transform(c1.begin(), c1.begin() + 2,
        c2.begin(), c3.begin(), cliext::modulus<int>());
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 2
3 1
1 0

multiplies (STL/CLR)

このテンプレート クラスによって記述されるファンクターは、呼び出されると、1 番目の引数と 2 番目を乗算して返します。 これを使用して、関数オブジェクトの引数の型を指定します。

構文

template<typename Arg>
    ref class multiplies
    { // wrap operator()
public:
    typedef Arg first_argument_type;
    typedef Arg second_argument_type;
    typedef Arg result_type;
    typedef Microsoft::VisualC::StlClr::BinaryDelegate<
        first_argument_type, second_argument_type, result_type>
        delegate_type;

    multiplies();
    multiplies(multiplies<Arg>% right);

    result_type operator()(first_argument_type left,
        second_argument_type right);
    operator delegate_type^();
    };

パラメーター

Arg
引数と戻り値の型。

メンバー関数

型の定義 説明
delegate_type 汎用デリゲートの型。
first_argument_type ファンクターの 1 番目の引数の型。
result_type ファンクターの結果の型。
second_argument_type ファンクターの 2 番目の引数の型。
メンバー 説明
multiplies ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^ ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、2 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、1 番目の引数と 2 番目を乗算して返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_multiplies.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(3);
    Myvector c2;
    c2.push_back(2);
    c2.push_back(1);
    Myvector c3(2, 0);

// display initial contents " 4 3" and " 2 1"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

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

// transform and display
    cliext::transform(c1.begin(), c1.begin() + 2,
        c2.begin(), c3.begin(), cliext::multiplies<int>());
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 3
2 1
8 3

negate (STL/CLR)

このテンプレート クラスによって記述されるファンクターは、呼び出されると、引数を否定して返します。 これを使用して、関数オブジェクトの引数の型を指定します。

構文

template<typename Arg>
    ref class negate
    { // wrap operator()
public:
    typedef Arg argument_type;
    typedef bool result_type;
    typedef Microsoft::VisualC::StlClr::UnaryDelegate<
        argument_type, result_type>
        delegate_type;

    negate();
    negate(negate<Arg>% right);

    result_type operator()(argument_type left);
    operator delegate_type^();
    };

パラメーター

Arg
引数の型。

メンバー関数

型の定義 説明
argument_type ファンクターの引数の型。
delegate_type 汎用デリゲートの型。
result_type ファンクターの結果の型。
メンバー 説明
negate ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^ ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、1 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、引数を否定して返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_negate.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(-3);
    Myvector c3(2, 0);

// display initial contents " 4 -3"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

// transform and display
    cliext::transform(c1.begin(), c1.begin() + 2,
        c3.begin(), cliext::negate<int>());
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 -3
-4 3

not_equal_to (STL/CLR)

テンプレート クラスは、呼び出されると、最初の引数が 2 番目の引数と等しくない場合にのみ true を返すファンクターを記述します。 これを使用して、関数オブジェクトの引数の型を指定します。

構文

template<typename Arg>
    ref class not_equal_to
    { // wrap operator()
public:
    typedef Arg first_argument_type;
    typedef Arg second_argument_type;
    typedef bool result_type;
    typedef Microsoft::VisualC::StlClr::BinaryDelegate<
        first_argument_type, second_argument_type, result_type>
        delegate_type;

    not_equal_to();
    not_equal_to(not_equal_to<Arg>% right);

    result_type operator()(first_argument_type left,
        second_argument_type right);
    operator delegate_type^();
    };

パラメーター

Arg
引数の型。

メンバー関数

型の定義 説明
delegate_type 汎用デリゲートの型。
first_argument_type ファンクターの 1 番目の引数の型。
result_type ファンクターの結果の型。
second_argument_type ファンクターの 2 番目の引数の型。
メンバー 説明
not_equal_to ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^ ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、2 引数のファンクターを記述します。 メンバー演算子 operator() を定義して、オブジェクトが関数として呼び出されると、最初の引数が 2 番目の引数と等しくない場合にのみ true を返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_not_equal_to.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(3);
    Myvector c2;
    c2.push_back(4);
    c2.push_back(4);
    Myvector c3(2, 0);

// display initial contents " 4 3" and " 4 4"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

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

// transform and display
    cliext::transform(c1.begin(), c1.begin() + 2,
        c2.begin(), c3.begin(), cliext::not_equal_to<int>());
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 3
4 4
0 1

not1 (STL/CLR)

ファンクターの unary_negate を生成します。

構文

template<typename Fun>
    unary_negate<Fun> not1(Fun% functor);

テンプレート パラメーター

Fun
ファンクターの型。

関数パラメーター

functor
ラップするファンクター。

解説

関数テンプレートが返します unary_negate<Fun>(functor)。 これは、1 引数のファンクターを、その論理 NOT を提供するファンクターにラップする便利な方法として使用できます。

// cliext_not1.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(0);
    Myvector c3(2, 0);

// display initial contents " 4 0"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

// transform and display
    cliext::logical_not<int> not_op;

    cliext::transform(c1.begin(), c1.begin() + 2, c3.begin(),
        cliext::unary_negate<cliext::logical_not<int> >(not_op));
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

// transform and display with function
    cliext::transform(c1.begin(), c1.begin() + 2, c3.begin(),
        cliext::not1(not_op));
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 0
1 0
1 0

not2 (STL/CLR)

ファンクターの binary_negate を生成します。

構文

template<typename Fun>
    binary_negate<Fun> not2(Fun% functor);

テンプレート パラメーター

Fun
ファンクターの型。

関数パラメーター

functor
ラップするファンクター。

解説

関数テンプレートが返します binary_negate<Fun>(functor)。 これは、2 引数のファンクターを、その論理 NOT を提供するファンクターにラップする便利な方法として使用できます。

// cliext_not2.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(3);
    Myvector c2;
    c2.push_back(4);
    c2.push_back(4);
    Myvector c3(2, 0);

// display initial contents " 4 3" and " 4 4"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

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

// transform and display
    cliext::less<int> less_op;

    cliext::transform(c1.begin(), c1.begin() + 2,
        c2.begin(), c3.begin(),
        cliext::binary_negate<cliext::less<int> >(less_op));
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

// transform and display with function
    cliext::transform(c1.begin(), c1.begin() + 2,
        c2.begin(), c3.begin(), cliext::not2(less_op));
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 3
4 4
1 0
1 0

plus (STL/CLR)

このテンプレート クラスによって記述されるファンクターは、呼び出されると、1 番目と 2 番目の引数を加算して返します。 これを使用して、関数オブジェクトの引数の型を指定します。

構文

template<typename Arg>
    ref class plus
    { // wrap operator()
public:
    typedef Arg first_argument_type;
    typedef Arg second_argument_type;
    typedef Arg result_type;
    typedef Microsoft::VisualC::StlClr::BinaryDelegate<
        first_argument_type, second_argument_type, result_type>
        delegate_type;

    plus();
    plus(plus<Arg>% right);

    result_type operator()(first_argument_type left,
        second_argument_type right);
    operator delegate_type^();
    };

パラメーター

Arg
引数と戻り値の型。

メンバー関数

型の定義 説明
delegate_type 汎用デリゲートの型。
first_argument_type ファンクターの 1 番目の引数の型。
result_type ファンクターの結果の型。
second_argument_type ファンクターの 2 番目の引数の型。
メンバー 説明
plus ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
operator delegate_type^ ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、2 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、1 番目と 2 番目の引数を加算して返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_plus.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(3);
    Myvector c2;
    c2.push_back(2);
    c2.push_back(1);
    Myvector c3(2, 0);

// display initial contents " 4 3" and " 2 1"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

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

// transform and display
    cliext::transform(c1.begin(), c1.begin() + 2,
        c2.begin(), c3.begin(), cliext::plus<int>());
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 3
2 1
6 4

unary_delegate (STL/CLR)

ジェネリック クラスは、1 つの引数デリゲートを記述します。 これを使用して、デリゲートの引数と戻り値の型を指定します。

構文

generic<typename Arg,
    typename Result>
    delegate Result unary_delegate(Arg);

パラメーター

Arg
引数の型。

Result
戻り値の型。

解説

ジェネリック デリゲートは、1 引数関数を記述します。

これらの関数テンプレートでは、次の手順を実行します。

unary_delegate<int, int> Fun1;

unary_delegate<int, int> Fun2;

この場合、型 Fun1Fun2 はシノニムです。

delegate int Fun1(int);

delegate int Fun2(int);

これらは同じ型ではありません。

// cliext_unary_delegate.cpp
// compile with: /clr
#include <cliext/functional>

int hash_val(wchar_t val)
    {
    return ((val * 17 + 31) % 67);
    }

typedef cliext::unary_delegate<wchar_t, int> Mydelegate;
int main()
    {
    Mydelegate^ myhash = gcnew Mydelegate(&hash_val);

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

unary_delegate_noreturn (STL/CLR)

ジェネリック クラスは、.. を返す 1 引数デリゲートを記述します void。 これを使用して、デリゲートの引数の型を指定します。

構文

generic<typename Arg>
    delegate void unary_delegate_noreturn(Arg);

パラメーター

Arg
引数の型。

解説

ジェネリック デリゲートは、を返す 1 引数関数を記述します void

これらの関数テンプレートでは、次の手順を実行します。

unary_delegate_noreturn<int> Fun1;

unary_delegate_noreturn<int> Fun2;

この場合、型 Fun1Fun2 はシノニムです。

delegate void Fun1(int);

delegate void Fun2(int);

これらは同じ型ではありません。

// cliext_unary_delegate_noreturn.cpp
// compile with: /clr
#include <cliext/functional>

void hash_val(wchar_t val)
    {
    System::Console::WriteLine("hash({0}) = {1}",
       val, (val * 17 + 31) % 67);
    }

typedef cliext::unary_delegate_noreturn<wchar_t> Mydelegate;
int main()
    {
    Mydelegate^ myhash = gcnew Mydelegate(&hash_val);

    myhash(L'a');
    myhash(L'b');
    return (0);
    }
hash(a) = 5
hash(b) = 22

unary_negate (STL/CLR)

このテンプレート クラスは、呼び出されると、格納されている 1 引数のファンクターの論理 NOT を返すファンクターを記述します。 これを使用して、関数オブジェクトの格納されているファンクターを指定します。

構文

template<typename Fun>
    ref class unary_negate
    { // wrap operator()
public:
    typedef Fun stored_function_type;
    typedef typename Fun::argument_type argument_type;
    typedef bool result_type;
    typedef Microsoft::VisualC::StlClr::UnaryDelegate<
        argument_type, result_type>
        delegate_type;

    unary_negate(Fun% functor);
    unary_negate(unary_negate<Fun>% right);

    result_type operator()(argument_type left);
    operator delegate_type^();
    };

パラメーター

Fun
格納されているファンクターの型。

メンバー関数

型の定義 説明
argument_type ファンクターの引数の型。
delegate_type 汎用デリゲートの型。
result_type ファンクターの結果の型。
メンバー 説明
unary_negate ファンクターを構築します。
Operator 説明
operator() 目的の関数を計算します。
delegate_type^ ファンクターをデリゲートにキャストします。

解説

このテンプレート クラスは、別の 1 引数のファンクターを格納する 1 引数のファンクターを記述します。 これによって定義されるメンバー演算子 operator() は、オブジェクトが関数として呼び出されると、格納されている 1 引数のファンクターの論理 NOT を返します。

型が delegate_type^ である関数引数としてオブジェクトを渡すこともでき、それは適切に変換されます。

// cliext_unary_negate.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>

typedef cliext::vector<int> Myvector;
int main()
    {
    Myvector c1;
    c1.push_back(4);
    c1.push_back(0);
    Myvector c3(2, 0);

// display initial contents " 4 0"
    for each (int elem in c1)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

// transform and display
    cliext::logical_not<int> not_op;

    cliext::transform(c1.begin(), c1.begin() + 2, c3.begin(),
        cliext::unary_negate<cliext::logical_not<int> >(not_op));
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();

// transform and display with function
    cliext::transform(c1.begin(), c1.begin() + 2, c3.begin(),
        cliext::not1(not_op));
    for each (int elem in c3)
        System::Console::Write(" {0}", elem);
    System::Console::WriteLine();
    return (0);
    }
4 0
1 0
1 0