🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2666

pointer to member function adaptor

#2666
From: Brian Michael Freyburger
Date: Mon, 20 Nov 1995 21:34
35 lines
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. ]
Technical Details
Message-ID: <FREYBURG.95Nov20132142@glitch.stanford.edu>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: freyburg@glitch.stanford.edu (Brian Michael Freyburger)
Newsgroups: comp.std.c++
Subject: pointer to member function adaptor
Date: 20 Nov 1995 21:34:51 GMT
Organization: Stanford University
Approved: matt@physics10.Berkeley.EDU (Matt Austern)
Message-ID: <FREYBURG.95Nov20132142@glitch.stanford.edu>
NNTP-Posting-Host: physics10.berkeley.edu