Reputation: 1534
I'm trying to understand the workings of std::decay a little better. Per cppreference it's supposed to remove const and volatile classification from the type as part of other transformations it does. However, below function displays "False", "True" vs. "True", "True" as one might expect. Can someone please clarify why the const is needed when matching against the decayed type here?
int main()
{
const char *p = "testing";
cout << "------------------" << endl;
cout << boolalpha << is_same<char *, decay_t<decltype(p)>>::value << endl;
cout << boolalpha << is_same<const char *, decay_t<decltype(p)>>::value << endl;
cout << "------------------" << endl;
}
Upvotes: 3
Views: 1103
Reputation: 117851
std::decay_t
would remove the const
from the pointer, had it been const
, not the type it's pointing at.
That is, a char* const
would decay into a char*
.
Upvotes: 5