共用方式為


binder2nd (STL/CLR)

樣板類別描述一個引數 functor,呼叫時,會傳回其預存的兩個引數 functor,以提供的第一個引數和其預存的第二個引數呼叫。 使用指定的預存的 functor 的角度來看一個函式物件。

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^();
    };

參數

  • 娛樂特區
    預存的 functor 型別。

成員函式

型別定義

描述

delegate_type

泛型委派型別。

first_argument_type

Functor 的第一個引數型別。

result_type

Functor 結果的型別。

second_argument_type

Functor 的第二個引數的型別。

stored_function_type

Functor 型別。

成員

描述

binder2nd

建構的 functor。

運算子

描述

operator)

計算所需的函式。

運算子 delegate_type^()

轉換成委派 functor。

備註

樣板類別描述一個引數 functor 儲存兩個引數 functor 和第二個引數。 它定義了成員運算子operator()這麼一來,該物件做為函式呼叫時,它會傳回呼叫預存的 functor 所提供的第一個引數而預存的第二個引數的結果。

您也可以傳遞物件做為函式引數,其型別是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); 
    } 
 
  

需求

標頭: < cliext/功能 >

Namespace: cliext

請參閱

參考

bind2nd (STL/CLR)