I’m trying to use std::mem_fun_ref (Yes, the deprecated
version. Reasons below) to call a member function through a proxy.
template<typename T>
struct proxy {
T& operator*() { return *t; }
T* operator->() { return t; }
// no address of etc
T* t;
};
struct A {void foo() {}};
int main()
{
A a;
proxy<A> pa = {&a};
std::mem_fun_ref_t<void, A>
fn = std::mem_fun_ref(&A::foo);
fn(pa); // borks
return 0;
}
This works well with C++11 std::mem_fn but not boost::mem_fn, but
I can use neither of those, as I need to specify the type of the
binder in another place and the type of the resulting binder is
unspecified for boost::mem_fn. This wouldn’t be a problem if I could
use decltype but I can’t as the code needs to be compatible with
C++03.
What is the easiest way to work around this? A custom
mem_fun_through_proxy?
Edit: Another caveat is that the proxy class cannot be changed.
As Georg recommended, I implemented my own solution. Here is the short version: