Introduction
The main reason for introducing std::enable_if_t<cond, T> as a shorter form of std::enable_if<cond, T>::type is not to shave only a 4-character number.
Since std::enable_if and other features of this type are mainly used in dependent contexts, it is rather painful to write (A) when (B) would be enough:
<sub> Example sub>
template<class T, class = typename std::enable_if<cond, T>::type>
template<class T, class = std::enable_if_t<cond, T>>
Dependent Names
We need a type name before std::enable_if , because ::type is a dependent name, and without it, the standard says that the expression should be parsed as if ::type were actually a value.
std::is_same<T, U>::value is really a value, so there is no need to use typename; which in turn means that we effectively shave just 4 characters. nothing more.
additional literature
- fooobar.com/questions/11848 / ...
So why is there no variable template for std :: is_same?
Just because there is no such great need, therefore, no one has suggested adding in time; since most of them are satisfied with the following alternatives:
std::is_same<T, U> {} == std::is_same<T, U>::value std::is_same<T, U> () == std::is_same<T, U>::value
additional literature
There is a proposal written by Stefan T. Lavavi to add template variables for suitable types.
Filip Rosรฉen - refp
source share