Topic: pointer to member function adaptor
Author: freyburg@glitch.stanford.edu (Brian Michael Freyburger)
Date: 1995/11/20 Raw View
Why doesn't STL have a pointer to member function adaptor, such as:
template <class Arg1, class Arg2, class Result>
class pointer_to_member_function : public binary_function<Arg1,Arg2,Result>
{
public:
explicit pointer_to_binary_function(Result (Arg1::*f)(Arg2)) : f(f)
{}
Result operator()(const Arg1& x, const Arg2& y) const
{ return x.*pf(y); }
};
template <class Arg1, class Arg2, class Result>
pointer_to_member_function<Arg1,Arg2,Result> ptr_fun(Result (Arg1::*f)(Arg2))
{
pointer_to_member_function<Arg1,Arg2,Result>(f);
}
Of course, there also could a pointer_to_unary_member_function, and a
pointer_to_void_member_function.
IMHO, this seems to be a very easy addition, as well as VERY useful
when you want to use anything in <algorithm>. [I have wanted it many
times, and after adding it myself, I use it all the time.]
Brian Freyburger
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]