In C++20, alias templates can have implicit deduction guides if it is applied.
Then, I have constructed a simple template alias which is ints
:
template <std::size_t N>
using ints = std::array<int, N>;
but:
ints{1, 2, 3, 4}
doesn't work, and GCC said:
- error: no matching function for call to
array(int, int, int, int)
- note: couldn't deduce template parameter
N
- note: mismatched types
std::array<int, N>
andint
I don't understand why it fails to compile.
And:
template <typename T>
using array_of_4 = std::array<T, 4>;
with
array_of_4{1, 2, 3, 4}
won't work either.
- Is it because
std::array
's deduction guide is user-provided? - If the above's answer is not true, then what would be the reason?
I have found a similar question regarding this issue: How to write deduction guidelines for aliases of aggregate templates?.
This concludes that, in standard, this code should be well-formed. Hence, GCC may have different implementations that prevent this code from compiling.