Perfect forwarding with multiple passes over input arguments
问题 Consider the following function accept that takes a "universal reference" of type T and forwards that to a parse<T>() function object with an overload for lvalues and one for rvalues: template<class T> void accept(T&& arg) { parse<T>()(std::forward<T>(arg), 0); // copy or move, depending on rvaluedness of arg } template<class T> class parse { // parse will modify a local copy or move of its input parameter void operator()(T const& arg, int n) const { /* optimized for lvalues */ } void