[英]Is placeholder for the deduced class type of non-type template parameter a C++20 feature?
With the addition of non-type template parameter of class type into the C++20 standard ( P0732R2 ) was introduced the possibility to declare a non-type template parameter using a placeholder for deduced class type for non-type template parameter [dcl.type.class.deduct]§2 :随着将 class 类型的非类型模板参数添加到 C++20 标准 ( P0732R2 ) 中,引入了使用非类型模板参数推导的 class 类型的占位符声明非类型模板参数的可能性[dcl. type.class.deduct]§2 :
A placeholder for a deduced class type can also be used in the type-specifier-seq in the new-type-id or type-id of a new-expression, as the simple-type-specifier in an explicit type conversion (functional notation), or as the type-specifier in the parameter-declaration of a template-parameter.
推导的 class 类型的占位符也可用于新表达式的新类型标识或类型标识中的类型说明符序列中,作为显式类型转换中的简单类型说明符(功能符号),或作为模板参数的参数声明中的类型说明符。
What is bolded is the addition of P0732R2 to the standard.加粗的是标准中增加了P0732R2 。 This allows such code:
这允许这样的代码:
template <class T>
struct x{
constexpr x(T){}
};
template <x v>
struct y {};
y <1> b;
Code that compiles with GCC.使用 GCC 编译的代码。
I thought about using this feature in new code, but there is 3 reasons that makes me think that actually this feature was intended to be removed from the standard:我曾考虑在新代码中使用此功能,但有 3 个原因让我认为该功能实际上是打算从标准中删除的:
It is not well integrated in the standard, for example, the unchanged standard wording for partial ordering of function templates makes it impossible to partially specialize a class template similar to y
because the synthesized argument for the template parameter v
must have a unique invented type (the synthesized argument used during partial ordering of class template specializations);它没有很好地集成在标准中,例如,对于 function 模板的部分排序的未更改标准措辞使得不可能部分特化类似于
y
的 class 模板,因为模板参数v
的合成参数必须具有唯一的发明类型(在 class 模板特化的部分排序期间使用的综合参数);
This syntax for placeholder inside a parameter looks like the "short concept syntax" of the concept-TS.参数内占位符的这种语法看起来像概念 TS 的“短概念语法”。 This syntax has been changed to the "adjective syntax"
concept-name auto
after the addition of P0732R2 to the standard;在标准中加入 P0732R2 后,此语法已更改为“形容词语法”
concept-name auto
;
On std-discussion, it looked like not all committee members are aware of this feature.在标准讨论中,似乎并非所有委员会成员都知道此功能。
Is placeholder for the deduced class type of non-type template parameter a C++20 feature?非类型模板参数的推导 class 类型的占位符是 C++20 功能吗?
Is placeholder for the deduced class type of non-type template parameter a C++20 feature?
非类型模板参数的推导 class 类型的占位符是 C++20 功能吗?
Yes.是的。 [temp.param]/6 is quite clear about this:
[temp.param]/6对此非常清楚:
A non-type template-parameter shall have one of the following (possibly cv-qualified) types:
非类型模板参数应具有以下类型之一(可能是 cv 限定的):
- a structural type (see below),
结构类型(见下文),
- a type that contains a placeholder type ([dcl.spec.auto]), or
包含占位符类型 ([dcl.spec.auto]) 的类型,或
- a placeholder for a deduced class type ([dcl.type.class.deduct]).
推导的 class 类型的占位符([dcl.type.class.deduct])。
As for your concerns.至于你的顾虑。
It is not well integrated in the standard, for example, the unchanged standard wording for partial ordering of function templates makes it impossible to partially specialize a class template [...]
它没有很好地集成到标准中,例如,对于 function 模板的部分排序的标准措辞没有改变,因此无法对 class 模板进行部分特化 [...]
Yes, language additions are frequently incomplete and lead to language issues.是的,语言添加经常不完整并导致语言问题。 A more pressing one is the limitation on what kinds of types can be used as non-type template parameters, a limitation that prohibits
std::string
, std::tuple
, and std::optional
and the moment.一个更紧迫的问题是对哪些类型可以用作非类型模板参数的限制,一个禁止
std::string
、 std::tuple
和std::optional
的限制和时刻。 These will be resolved in due time.这些将在适当的时候得到解决。
This syntax for placeholder inside a parameter looks like the "short concept syntax" of the concept-TS
参数内占位符的这种语法看起来像 concept-TS 的“短概念语法”
This is just what CTAD syntax looks like.这正是 CTAD 语法的样子。
On std-discussion, it looked like not all committee members are aware of this feature.
在标准讨论中,似乎并非所有委员会成员都知道此功能。
So?所以?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.