I need to implement a no-op in C++ which preserves all type extensions (const, rvalue ref, lvalue ref). Can I do this as follows?
template<class T>
T && noop (T && t) { return std::forward<T> (t); }
and call it like
... noop (value) ...
(i.e. use type inference)? I.e. does noop (value) have exactly the same type as value?
Yes it does. However, it’s no different from just calling std::forward in the client code itself (except that with std::forward there’s no automatic template argument deduction).