Please consider this code:
template<typename T>
void f(T x) {
std::cout << sizeof(T);
}
int array[27];
f(array);
f<typeof(array)>(array);
This will print
8 (or 4)
108
In the first case, the array obviously decays to a pointer and T becomes int*
. In the second case, T is forced to int[27]
.
Is the order of decay/substitution implementation defined? Is there a more elegant way to force the type to int[27]
? Besides using std::vector?