Thread View: comp.std.c++
1 messages
1 total messages
Started by Brian Michael Freyburger
Mon, 20 Nov 1995 21:34
pointer to member function adaptor
Author: Brian Michael Freyburger
Date: Mon, 20 Nov 1995 21:34
Date: Mon, 20 Nov 1995 21:34
35 lines
1520 bytes
1520 bytes
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. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads