It is possible to store and wrap member functions with std::mem_fn?
In C you can use offsetof(...) on a data member to crudely wrap it (but only for some types). Is it possible to wrap a data member in C++? What’s the cleanest way?
For example:
class X
{
...
M m;
...
};
mem_var<M> xm = &X::m;
int main()
{
X x = ...;
M i = ...;
xm(x) = i; // same as x.m = i
cout << xm(x); // same as cout << x.m
}
Yes, you can do it with…
std::mem_fn.Demo: http://ideone.com/40nI2