[英]std::decay and removing const qualifiers
I'm trying to understand the workings of std::decay a little better.我试图更好地理解 std::decay 的工作原理。 Per cppreference it's supposed to remove const and volatile classification from the type as part of other transformations it does.每个 cppreference 它应该从类型中删除 const 和 volatile 分类,作为它所做的其他转换的一部分。 However, below function displays "False", "True" vs. "True", "True" as one might expect.但是,在 function 下方显示“假”、“真”与“真”、“真”,正如人们所期望的那样。 Can someone please clarify why the const is needed when matching against the decayed type here?有人可以澄清为什么在与衰减类型匹配时需要 const 吗?
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;
}
std::decay_t
would remove the const
from the pointer, had it been const
, not the type it's pointing at. std::decay_t
将从指针中删除const
,如果它是const
,而不是它指向的类型。
That is, a char* const
would decay into a char*
.也就是说, char* const
会衰减为char*
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.