Why does assigning std::ref not change the value of the referenced object?
A small modification to f2 provides the clue: template<class T> void f2(T arg) { arg.get() = xx; } This now does what you expect. This has happened because std::ref returns a std::reference_wrapper<> object. The assignment operator of which rebinds the wrapper. (see http://en.cppreference.com/w/cpp/utility/functional/reference_wrapper/operator%3D) It does not make an assignment to the wrapped reference. In the … Read more