Is there a simple way to forward to a member function with a matching function signature?
typedef std::tr1::function<int(int,int,int,int)> TheFn;
class C
{
int MemberFn(int,int,int,int) { return 0; }
TheFn getFn() {
//is there a simpler way to write the following line?
return [this](int a,int b,int c,int d){ return this->MemberFn(a,b,c,d); };
}
};
Have you tried
bind?I have left the full qualification of all elements, but
std::placeholdersapplied so many times don’t really help readability… I guess ausing std::placeholderswould not hurt at all:EDIT: To make it closer to the question code, so that it is clearer that this has the exact same functionality that the original code:
As you can see in both cases you are doing the same. I have used private and public methods for the example to show that when you
bind, the member method access level is checked at the place of bind, not at the place of call. So even ifMemberFnis private within the class you can call it through the binded functor. If the member is public, you can actually bind from outside of the class.