If you want to prevent someone form using this alias with non-arithmetic types, then you did it wrong.
Your code will allow any type that is a valid template argument and can be constructed from bool
and that's all.
The proper solution would be something like this:
template <typename T, std::size_t n>
using NumericArray = std::enable_if_t<std::is_arithmetic<T>::value, std::array<T, n>>;
Why your code doesn't work:
Look at this part:
template<typename T, std::size_t n, T = std::is_arithmetic<T>::value>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It creates an unnamed template argument of type T and sets a default value for it.
Even if std::is_arithmetic<T>::value
is false, the code will compile as long as T
can be constructed from bool
.
Of course, T
must be also usable as a template argument. (That's why float
does not work. Floating-point types can't be template arguments. See this: Why can't I use float value as a template parameter?)
Again, there is just no reason for the compiler to generate any errors if std::is_arithmetic<T>::value
is false.
For example, your code will allow following type:
struct S
{
constexpr S(bool) {}
};