Compartilhar via


binder2nd (STL/CLR)

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at binder2nd (STL/CLR).

The template class describes a one-argument functor that, when called, returns its stored two-argument functor called with the supplied first argument and its stored second argument. You use it specify a function object in terms of its stored functor.

Syntax

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

Parameters

Fun
The type of the stored functor.

Member Functions

Type Definition Description
delegate_type The type of the generic delegate.
first_argument_type The type of the functor first argument.
result_type The type of the functor result.
second_argument_type The type of the functor second argument.
stored_function_type The type of the functor.
Member Description
binder2nd Constructs the functor.
Operator Description
operator() Computes the desired function.
operator delegate_type^() Casts the functor to a delegate.

Remarks

The template class describes a one-argument functor that stores a two-argument functor and a second argument. It defines the member operator operator() so that, when the object is called as a function, it returns the result of calling the stored functor with the supplied first argument and the stored second argument.

You can also pass the object as a function argument whose type is delegate_type^ and it will be converted appropriately.

Example

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

Requirements

Header: <cliext/functional>

Namespace: cliext

See Also

bind2nd (STL/CLR)