Why is type deduction on const char[] different to const char *?
why doesn't the
const
qualify the whole array type
Because for array type,
(emphasis mine)
Applying cv-qualifiers to an array type (through typedef or template type manipulation) applies the qualifiers to the element type, but any array type whose elements are of cv-qualified type is considered to have the same cv-qualification.
// a and b have the same const-qualified type "array of 5 const char" typedef const char CC; CC a[5] = {}; typedef char CA[5]; const CA b = {};
That means when T
is char[7]
T const
leads to the type char const[7]
, then T const&
(i.e. a
's type) is char const (&)[7]
.
On the other hand, when you pass the array s
with type const char[7]
, the array is considered as const-qualified too. So given the parameter type T const&
, T
is deduced as char[7]
(but not char const[7]
).