1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| // TEMPLATE CLASS binder2nd
template<class _Bfn>
class binder2nd_mod: public std::unary_function<typename _Bfn::first_argument_type, typename _Bfn::result_type>
{
protected:
_Bfn op;
typename _Bfn::second_argument_type value;
public:
binder2nd_mod(_Bfn _X, typename _Bfn::second_argument_type _Y)
: op(_X), value(_Y) {}
result_type operator()(const argument_type & _X) const
{ return (op(_X, value)); }
};
// TEMPLATE FUNCTION bind2nd
template<class _Bfn, class _Ty>
inline binder2nd_mod<_Bfn> bind2nd_mod(_Bfn _X, const _Ty & _Y)
{ return (binder2nd_mod<_Bfn>(_X,_Y)); }
template<class _Result, class _Ty, class _Arg>
class const_mem_fun1_ref_mod_t: public std::binary_function<_Ty, _Arg, _Result>
{ // functor adapter (*left.*pfunc)(val), const *pfunc
private:
_Result (_Ty::*_Pmemfun)(_Arg) const; // the member function pointer
public:
explicit const_mem_fun1_ref_mod_t(_Result (_Ty::*_Pm)(_Arg) const)
: _Pmemfun(_Pm) // construct from pointer
{}
_Result operator()(const _Ty & _Left, _Arg _Right) const
{ // call function with operand
return ((_Left.*_Pmemfun)(_Right));
}
};
template<class _Result, class _Ty, class _Arg>
inline const_mem_fun1_ref_mod_t<_Result, _Ty, _Arg> mem_fun_ref_mod(_Result (_Ty::*_Pm)(_Arg) const)
{ // return a const_mem_fun1_ref_t functor adapter
return (const_mem_fun1_ref_mod_t<_Result, _Ty, _Arg>(_Pm));
} |