The equivalent of std::decay happens to argument types for functions. (It's actually the reverse, std::decay is modeled after what functions arguments do.)
The outermost const will be dropped from the signature. By outermost, think of types as envelopes composed over different types. A pointer to const int is a different type than a pointer to int, and will result in a different function signature. (With a pointer, you can think of the pointer itself as the outer thing, and what it points to is "inner" and not modified.)
const int
- becomes just int
int *
is unchanged and remains int *
const int *
is unchanged and remains const int *
- const is on the int, not the pointer, and only the outermost const is dropped
int const *
is unchanged and remains int const *
- const is on the int, not the pointer, and only the outermost const is dropped. (Note, this is 100% identical in meaning as const int *
)
int * const
- changes to int *
- because const qualifies the outermost pointer
int * const * const
becomes int * const *
- outer const is dropped on outer pointer, inner const is not dropped on the inner pointer.
const int * const * const
becomes const int * const *
- outer const is dropped on outer pointer, inner const is not dropped on the inner pointer, and const is also kept on the internal-most int
MyTemplate<const T>
- unchanged, remains MyTemplate<const T>
, because the const isn't on the outer type, but nestled in a template parameter
So yes, const does affect type, but not in the simple case like you tried. Only when it's contained inside of a type, not affecting the outermost type.
If you read types from right-to-left it can help. If the rightmost thing in a type specifier is a const, it is always dropped (example int * const
). If the leftmost thing is const, it is only dropped if the thing it is qualifying is the rightmost thing in the type (example const int
, the leftmost thing is const and it affects the int to its right AND the int to its right is the rightmost thing in the type.) (example 2: const * int
not dropped, because leftmost const modifies the thing to its right that is not the rightmost thing in the type.)