Fredrik Blomqvist wrote: > What's the rationale for mem_fn to (in the case of data members) make > it's return_type a reference?
It's because mem_fn returns a reference. #include <boost/mem_fn.hpp> #include <iostream> template<class F, class A1> typename F::result_type call(F f, A1 a1) { return f(a1); } struct X { int i; }; int main() { X x = { 5 }; boost::mem_fn(&X::i)(&x) = 42; int const * p = &call(boost::mem_fn(&X::i), &x); std::cout << *p << std::endl; } A data member is treated as if it was a member function that returns a reference to the member. Exposing a const reference as result_type has its limitations since mem_fn tries to preserve the (non-)constness of the data member, but it's as close as it can get. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost