Introduction
The primary reason for introducing std::enable_if_t<cond, T>
as a shorter form ofstd::enable_if<cond, T>::type
is not to shave of a mere count of 4 characters.
Since std::enable_if
, and other type-traits of its kind, is mostly used in dependent contexts, it is quite painful having to write (A) when (B) would suffice:
Example
template<class T, class = typename std::enable_if<cond, T>::type> // (A)
struct A;
template<class T, class = std::enable_if_t<cond, T>> // (B)
struct A;
Dependent Names
We need typename prior to std::enable_if
because ::type
is a dependent-name, and without it the Standard says that the expression shall be parsed as if ::type
is actually a value.
std::is_same<T, U>::value
is really a value, so there's no need for the use of typename; which in turns mean that we are effectively shaving of a mere count of 4 characters.. nothing more.
Further Reading
So, why isn't there a variable-template for std::is_same?
Simply because there isn't that big of a need, so no one did propose the addition in time; as most are satisfied with the below alternatives:
std::is_same<T, U> {} == std::is_same<T, U>::value
std::is_same<T, U> () == std::is_same<T, U>::value
Further Reading
There is a proposal, written by Stephan T. Lavavej, to add variable-templates for the suitable type-traits.