std::remove_cv 应该在 const T 数组上生成什么类型?
What type should std::remove_cv produce on an array of const T?
std::remove_cv<const int[3]>
应该生产什么类型的? int[3]
或 const int[3]
?
const int[3]
是 array of 3 const int
对吗?并且没有顶级 cv 限定符。那么它不应该产生const int[3]
吗?我认为 gcc/libstdc++ 的最新版本正在生成 int[3]
。这是一个错误吗?为什么/为什么不?
N4140 §3.9.3 [basic.type.qualifier]/p5,强调我的:
Cv-qualifiers applied to an array type attach to the underlying
element type, so the notation “cv T
,” where T
is an array type,
refers to an array whose elements are so-qualified. An array type
whose elements are cv-qualified is also considered to have the same
cv-qualifications as its elements. [ Example:
typedef char CA[5];
typedef const char CC;
CC arr1[5] = { 0 };
const CA arr2 = { 0 };
The type of both arr1
and arr2
is “array of 5 const char
,” and
the array type is considered to be const
-qualified. —end example ]
另见 CWG issue 1059。
std::remove_cv<const int[3]>
应该生产什么类型的? int[3]
或 const int[3]
?
const int[3]
是 array of 3 const int
对吗?并且没有顶级 cv 限定符。那么它不应该产生const int[3]
吗?我认为 gcc/libstdc++ 的最新版本正在生成 int[3]
。这是一个错误吗?为什么/为什么不?
N4140 §3.9.3 [basic.type.qualifier]/p5,强调我的:
Cv-qualifiers applied to an array type attach to the underlying element type, so the notation “
cv T
,” whereT
is an array type, refers to an array whose elements are so-qualified. An array type whose elements are cv-qualified is also considered to have the same cv-qualifications as its elements. [ Example:typedef char CA[5]; typedef const char CC; CC arr1[5] = { 0 }; const CA arr2 = { 0 };
The type of both
arr1
andarr2
is “array of 5const char
,” and the array type is considered to beconst
-qualified. —end example ]
另见 CWG issue 1059。