http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52917

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-10 
11:23:51 UTC ---
(In reply to comment #3)
> Ok, I didn't know about the defect report and resolution yet.
> I must admit that I quite like the <int&()> syntax.

It's a peculiarity of the C++ grammar, the function parameter R T::*pm is a
pointer to member, with T deduced as X and R deduced as the function type
int&()

If it helps, consider that you can declare X::get() like this:

#include <functional>

struct X
{
  int a;
  typedef int& func_type();
  func_type get;
};

int& X::get() { return a; }

And then you can use the typedef with mem_fn:

auto pm = std::mem_fn<X::func_type>(&X::get);


> I added a remark about the defect and a short example to
> http://en.cppreference.com/w/cpp/utility/functional/mem_fn

N.B. That page has a heading "Execptions"

> And I noted that the most c++11-ish code would be anyway:
> 
> auto y = [] (X& x) {return x.get();};

In most cases yes, but mem_fn has the advantage it always returns the same
type, whereas two lambda expressions produce two different closure types even
if the expressions are identical, and mem_fn might be easier to use in
late-specified return types.

Reply via email to