共用方式為


binder1st (STL/CLR)

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

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

參數

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

成員函式

型別定義

描述

delegate_type

泛型委派型別。

first_argument_type

Functor 的第一個引數型別。

result_type

Functor 結果的型別。

second_argument_type

Functor 的第二個引數的型別。

stored_function_type

Functor 型別。

成員

描述

binder1st

建構的 functor。

運算子

描述

operator)

計算所需的函式。

運算子 delegate_type^()

轉換成委派 functor。

備註

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

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

需求

標頭: < cliext/功能 >

Namespace: cliext

請參閱

參考

bind1st (STL/CLR)