What is the difference between using "typename" before the return type of a function and without using it at the declaration of a function like the following below?
And what is different if we don't use it at all?
template< class T > typename std::remove_reference<T>::type&& move( T&& t );
template< class T > std::remove_reference_t<T>&& move( T&& t ) ;
In
std::remove_reference<T>::type, the::typeis dependent on the template typeT. The compiler (until C++20), doesn't know this, and one needs to tell that, so that compiler understands it is a type. That is the reason whytypenamekeyword is.Read more: When is the "typename" keyword necessary?
The second
std::remove_reference_t<T>, is a template type alias, which looks like:And allows you to save some typing (aka. for convenience).
Since C++20, you can simply write with or without
typenamekeyword, prior to that compiler may not interpret it as a type.Read more: Why don't I need to specify "typename" before a dependent type in C++20?