Share via


functional (STL/CLR)

包含 STL/CLR 標頭 <cliext/functional> ,以定義功能類別範本和相關範本委派和函式。

語法

#include <functional>

需求

標頭: < cliext/functional>

命名空間:cliext

宣告

委派 描述
binary_delegate (STL/CLR) 雙引數委派。
binary_delegate_noreturn (STL/CLR) 傳回 void 的雙引數委派。
unary_delegate (STL/CLR) 一個引數委派。
unary_delegate_noreturn (STL/CLR) 傳回 void 的一個引數委派。
類別 描述
binary_negate (STL/CLR) 用來否定雙引數運算函式的 Functor。
binder1st (STL/CLR) 將第一個引數系結至雙引數運算函式的 Functor。
binder2nd (STL/CLR) 將第二個引數系結至雙引數運算函式的 Functor。
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) 邏輯和函式。
logical_not (STL/CLR) 邏輯 NOT 函式。
logical_or (STL/CLR) 邏輯 OR 函式。
minus (STL/CLR) 減去運算函式。
modulus (STL/CLR) 模數運算函式。
multiplies (STL/CLR) 相乘運算函式。
negate (STL/CLR) 用來傳回其引數否定的 Functor。
not_equal_to (STL/CLR) 不等於比較運算函式。
plus (STL/CLR) 新增 functor。
unary_negate (STL/CLR) 用來否定一個引數運算函式的 Functor。
函式 描述
bind1st (STL/CLR) 為引數和 functor 產生 binder1st。
bind2nd (STL/CLR) 為引數和 functor 產生 binder2nd。
not1 (STL/CLR) 產生函式unary_negate。
not2 (STL/CLR) 產生函式binary_negate。

成員

binary_delegate (STL/CLR)

泛型類別描述兩個引數委派。 您可以使用它來指定委派,以其引數和傳回型別來指定委派。

語法

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

參數

Arg1
第一個引數的類型。

Arg2
第二個引數的類型。

Result
傳回類型。

備註

泛型委派描述雙引數函式。

在這些函式範本中:

binary_delegate<int, int, int> Fun1;

binary_delegate<int, int, int> Fun2;

Fun1 別和 Fun2 是同義字,同時為:

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)

泛型類別描述傳回 void 的雙引數委派。 您可以使用它來指定委派,就其引數而言。

語法

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

參數

Arg1
第一個引數的類型。

Arg2
第二個引數的類型。

備註

泛型委派描述傳回 void 的雙引數函式。

在這些函式範本中:

binary_delegate_noreturn<int, int> Fun1;

binary_delegate_noreturn<int, int> Fun2;

Fun1 別和 Fun2 是同義字,同時為:

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)

樣板類別描述一個函式,在呼叫 時,會傳回其預存雙引數 functor 的邏輯 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 函式第一個引數的類型。
result_type 函式結果的類型。
second_argument_type functor 第二個引數的類型。
stored_function_type 函式的類型。
member 描述
binary_negate 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^() 將函式轉換成委派。

備註

範本類別描述儲存另一個雙引數函式的雙引數函式。 它會定義成員運算子 operator() ,如此一來,當物件呼叫為函式時,它會傳回以兩個引數呼叫之預存函式的邏輯 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 引數和 functor 產生 。

語法

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

範本參數

Arg
引數型別。

Fun
函式的類型。

函式參數

functor
要包裝的函式。

left
要包裝的第一個引數。

備註

函式範本會傳 binder1st<Fun>(functor, left) 回 。 您可以使用它作為一種方便的方式,將雙引數函式及其第一個引數包裝在一個引數的函式中,以第二個引數呼叫它。

範例

// 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 引數和 functor 產生 。

語法

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

範本參數

Arg
引數型別。

Fun
函式的類型。

函式參數

functor
要包裝的函式。

right
要包裝的第二個引數。

備註

函式範本會傳 binder2nd<Fun>(functor, right) 回 。 您可以使用它作為一個便利的方式,將雙引數函式及其第二個引數包裝在一個引數運算函式中,以第一個引數呼叫它。

範例

// 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)

樣板類別描述一個引數運算函式,呼叫時會傳回其預存的雙引數函式,其儲存的第一個引數和提供的第二個引數。 您可以使用它指定函式物件,以儲存的函式函式來指定函式物件。

語法

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 函式第一個引數的類型。
result_type 函式結果的類型。
second_argument_type functor 第二個引數的類型。
stored_function_type 函式的類型。
member 描述
binder1st 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^() 將函式轉換成委派。

備註

範本類別描述一個引數運算函式,可儲存兩個引數的函式和第一個引數。 它會定義成員運算子 operator() ,如此一來,當物件呼叫為函式時,它會傳回使用預存的第一個引數和提供的第二個引數呼叫預存函式的結果。

您也可以將 物件當做函式引數傳遞,其類型為 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)

樣板類別描述一個引數運算函式,當呼叫 時,會傳回其預存的雙引數函式,該函式會使用提供的第一個引數和其儲存的第二個引數來呼叫。 您可以使用它指定函式物件,以儲存的函式函式來指定函式物件。

語法

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 函式第一個引數的類型。
result_type 函式結果的類型。
second_argument_type functor 第二個引數的類型。
stored_function_type 函式的類型。
member 描述
binder2nd 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^() 將函式轉換成委派。

備註

範本類別描述一個引數函式,可儲存兩個引數運運算元和第二個引數。 它會定義成員運算子 operator() ,如此一來,當物件呼叫為函式時,它會傳回使用所提供第一個引數和預存第二個引數呼叫預存函式的結果。

您也可以將 物件當做函式引數傳遞,其類型為 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)

樣板類別描述一個函式,呼叫時會傳回除以第二個引數的第一個引數。 您可以使用它來指定函式物件,就其引數類型而言。

語法

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 函式第一個引數的類型。
result_type 函式結果的類型。
second_argument_type functor 第二個引數的類型。
member 描述
divides 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^() 將函式轉換成委派。

備註

範本類別描述雙引數運算函式。 它會定義成員運算子 operator() ,如此一來,當物件呼叫為函式時,它會傳回除以第二個引數的第一個引數。

您也可以將 物件當做函式引數傳遞,其類型為 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)

樣板類別描述當呼叫時,只有在第一個引數等於第二個引數時,才會傳回 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 函式第一個引數的類型。
result_type 函式結果的類型。
second_argument_type functor 第二個引數的類型。
member 描述
equal_to 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^() 將函式轉換成委派。

備註

範本類別描述雙引數運算函式。 它會定義成員運算子 operator() ,如此一來,當物件呼叫為函式時,只有在第一個引數等於第二個引數時,才會傳回 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)

樣板類別描述當呼叫時,只有在第一個引數大於第二個引數時,才會傳回 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 函式第一個引數的類型。
result_type 函式結果的類型。
second_argument_type functor 第二個引數的類型。
member 描述
greater 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^ 將函式轉換成委派。

備註

範本類別描述雙引數運算函式。 它會定義成員運算子 operator() ,如此一來,當物件呼叫為函式時,只有在第一個引數大於第二個引數時,才會傳回 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)

樣板類別描述當呼叫時,只有在第一個引數大於或等於第二個引數時,才會傳回 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 函式第一個引數的類型。
result_type 函式結果的類型。
second_argument_type functor 第二個引數的類型。
member 描述
greater_equal 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^ 將函式轉換成委派。

備註

範本類別描述雙引數運算函式。 它會定義成員運算子 operator() ,如此一來,當物件呼叫為函式時,只有在第一個引數大於或等於第二個引數時,才會傳回 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)

樣板類別描述當呼叫時,只有在第一個引數小於第二個引數時,才會傳回 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 函式第一個引數的類型。
result_type 函式結果的類型。
second_argument_type functor 第二個引數的類型。
member 描述
less 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^ 將函式轉換成委派。

備註

範本類別描述雙引數運算函式。 它會定義成員運算子 operator() ,如此一來,當物件呼叫為函式時,只有在第一個引數小於第二個引數時,才會傳回 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)

樣板類別描述當呼叫時,只有在第一個引數小於或等於第二個引數時,才會傳回 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 函式第一個引數的類型。
result_type 函式結果的類型。
second_argument_type functor 第二個引數的類型。
member 描述
less_equal 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^ 將函式轉換成委派。

備註

範本類別描述雙引數運算函式。 它會定義成員運算子 operator() ,如此一來,當物件呼叫為函式時,只有當第一個引數小於或等於第二個引數時,才會傳回 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)

樣板類別描述當呼叫時,只有在第一個引數和第二個測試都傳回 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 函式第一個引數的類型。
result_type 函式結果的類型。
second_argument_type functor 第二個引數的類型。
member 描述
logical_and 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^ 將函式轉換成委派。

備註

範本類別描述雙引數運算函式。 它會定義成員運算子 operator() ,如此一來,當物件呼叫為函式時,只有在第一個引數和第二個測試都傳回 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 functor 引數的類型。
delegate_type 泛型委派的類型。
result_type 函式結果的類型。
member 描述
logical_not 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^ 將函式轉換成委派。

備註

範本類別描述一個引數運算函式。 它會定義成員運算子 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)

樣板類別描述函式,只有在第一個引數或第二個引數測試為 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 函式第一個引數的類型。
result_type 函式結果的類型。
second_argument_type functor 第二個引數的類型。
member 描述
logical_or 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^ 將函式轉換成委派。

備註

範本類別描述雙引數運算函式。 它會定義成員運算子 operator() ,以便在物件呼叫為函式時,只有在第一個引數或第二個測試為 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)

樣板類別描述呼叫時傳回第一個引數減去第二個引數的函式。 您可以使用它來指定函式物件,就其引數類型而言。

語法

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 函式第一個引數的類型。
result_type 函式結果的類型。
second_argument_type functor 第二個引數的類型。
member 描述
minus 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^ 將函式轉換成委派。

備註

範本類別描述雙引數運算函式。 它會定義成員運算子 operator() ,以便在呼叫 物件做為函式時,傳回第一個引數減去第二個引數。

您也可以將 物件當做函式引數傳遞,其類型為 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)

樣板類別描述呼叫時傳回第一個引數模數的第二個函式。 您可以使用它來指定函式物件,就其引數類型而言。

語法

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 函式第一個引數的類型。
result_type 函式結果的類型。
second_argument_type functor 第二個引數的類型。
member 描述
modulus 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^ 將函式轉換成委派。

備註

範本類別描述雙引數運算函式。 它會定義成員運算子 operator() ,如此一來,當物件呼叫為函式時,它會傳回第一個引數模數第二個。

您也可以將 物件當做函式引數傳遞,其類型為 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)

樣板類別描述一個函式,呼叫時會傳回第一個引數第二個引數。 您可以使用它來指定函式物件,就其引數類型而言。

語法

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 函式第一個引數的類型。
result_type 函式結果的類型。
second_argument_type functor 第二個引數的類型。
member 描述
multiplies 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^ 將函式轉換成委派。

備註

範本類別描述雙引數運算函式。 它會定義成員運算子 operator() ,如此一來,當物件呼叫為函式時,它會傳回第一個引數次第二個引數。

您也可以將 物件當做函式引數傳遞,其類型為 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 functor 引數的類型。
delegate_type 泛型委派的類型。
result_type 函式結果的類型。
member 描述
negate 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^ 將函式轉換成委派。

備註

範本類別描述一個引數運算函式。 它會定義成員運算子 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)

樣板類別描述當呼叫時,只有在第一個引數不等於第二個引數時,才會傳回 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 函式第一個引數的類型。
result_type 函式結果的類型。
second_argument_type functor 第二個引數的類型。
member 描述
not_equal_to 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^ 將函式轉換成委派。

備註

範本類別描述雙引數運算函式。 它會定義成員運算子 operator() ,如此一來,當物件呼叫為函式時,只有在第一個引數不等於第二個引數時,才會傳回 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) 回 。 您可以使用它做為方便的方式,將一個引數函式包裝在提供其邏輯 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) 回 。 您可以使用它作為一種方便的方式,將雙引數函式包裝在提供其邏輯 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)

樣板類別描述呼叫時傳回第一個引數加上第二個引數的函式。 您可以使用它來指定函式物件,就其引數類型而言。

語法

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 函式第一個引數的類型。
result_type 函式結果的類型。
second_argument_type functor 第二個引數的類型。
member 描述
plus 建構函式。
運算子 描述
operator() 計算所需的函式。
operator delegate_type^ 將函式轉換成委派。

備註

範本類別描述雙引數運算函式。 它會定義成員運算子 operator() ,以便當物件呼叫為函式時,它會傳回第一個引數加上第二個引數。

您也可以將 物件當做函式引數傳遞,其類型為 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)

泛型類別描述一個引數委派。 您可以使用它來指定委派,以其引數和傳回型別來指定委派。

語法

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

參數

Arg
引數型別。

Result
傳回類型。

備註

泛型委派描述一個引數函式。

在這些函式範本中:

unary_delegate<int, int> Fun1;

unary_delegate<int, int> Fun2;

Fun1 別和 Fun2 是同義字,同時為:

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)

泛型類別描述傳回 void 的一個引數委派。 您可以使用它來指定委派,就其引數類型而言。

語法

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

參數

Arg
引數型別。

備註

泛型委派描述會傳回 void 的一個引數函式。

在這些函式範本中:

unary_delegate_noreturn<int> Fun1;

unary_delegate_noreturn<int> Fun2;

Fun1 別和 Fun2 是同義字,同時為:

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)

樣板類別描述一個函式,在呼叫 時,會傳回其預存單一引數函式的邏輯 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 functor 引數的類型。
delegate_type 泛型委派的類型。
result_type 函式結果的類型。
member 描述
unary_negate 建構函式。
運算子 描述
operator() 計算所需的函式。
delegate_type^ 將函式轉換成委派。

備註

範本類別描述一個引數運算函式,可儲存另一個引數運算函式。 它會定義成員運算子 operator() ,如此一來,當呼叫 物件做為函式時,它會傳回以 引數呼叫之預存函式的邏輯 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