This is part of my weekly C++ posts based on the daily C++ tips I make at my work. I strongly recommend this practice. If you dont have it in your company start it.
1. std::forward
std::forward helps ... forward a T&& function argument as-is to another function. In the following example:
arg is treated as lvalue and will call the T& overload of foo. However if we pass a temporary to choose_foo we probably want to call the T&& overload of foo (if any). To fix this we use std::forward:template<class T>void choose_foo(T&& arg){foo(arg);}
template<class T>void choose_foo(T&& u){foo(std::forward<T>(u));}