/**
* 自定义函数适配器,该函数适配器会将二元函数对象变成一元函数对象
*/
template<typename BinaryFunction>
class MyBinder2nd : public unary_function<typename BinaryFunction::first_argument_type, typename BinaryFunction::result_type>{
public:
MyBinder2nd(BinaryFunction& bf, const typename BinaryFunction::second_argument_type& arg_2){
this->bf = bf;
this->arg_2 = arg_2;
}
typename BinaryFunction::result_type operator()(typename BinaryFunction::first_argument_type& arg_1){
return bf(arg_1, arg_2);
}
protected:
BinaryFunction bf;
typename BinaryFunction::second_argument_type arg_2;
};
void test10(){
plus<int> pl;
/*int result1 = pl(3, 4);
cout << result1 << endl;*/
MyBinder2nd<plus<int>> my_bind(pl, 10);
int x = 129;
int result2 = my_bind(x);
cout << result2 << endl;
}