decltype(void())中的void()到底是什么意思? [英] What does the void() in decltype(void()) mean exactly?
问题描述
This is a follow-up of this question, more precisely of the comments of this answer.
decltype(void())
中的void()
到底代表什么?
它代表函数类型,表达式还是其他?
What does the void()
in decltype(void())
represent exactly?
Does it represent a function type, an expression or whatever?
推荐答案
使用超链接的C ++语法, decltype(void())
的解析是:
decltype( expression )
decltype( assignment-expression )
decltype( conditional-expression )
...许多涉及操作顺序的步骤都在这里...
... lots of steps involving order of operations go here ...
decltype( postfix-expression )
decltype( simple-type-specifier ( expression-listopt ) )
decltype( void() )
所以void()
在这里是 expression
的一种,尤其是
So void()
is a kind of expression
here, in particular a postfix-expression
.
具体请引用2011 ISO C ++标准的5.2.3节[expr.type.conf]第2段:
Specifically, quoting section 5.2.3 [expr.type.conf] paragraph 2 of the 2011 ISO C++ standard:
表达式
T()
,其中T
是简单类型说明符或 typename-specifier 用于非数组完整对象类型或(可能具有cv限定)void
类型,可创建 指定的类型,它是值初始化的(8.5;不进行初始化 完成void()
情况.
The expression
T()
, whereT
is a simple-type-specifier or typename-specifier for a non-array complete object type or the (possibly cv-qualified)void
type, creates a prvalue of the specified type, which is value-initialized (8.5; no initialization is done for thevoid()
case).
因此,void()
是类型void
的表达式,就像int()
是类型int
的表达式(值0
)一样.显然,void表达式没有任何值,但是这里是decltype
的操作数,因此不对其进行求值. decltype
仅引用其操作数的类型,而不是其值.
So void()
is an expression of type void
, just as int()
is an expression of type int
(with value 0
). Clearly a void expression has no value, but here it's the operand of decltype
, so it's not evaluated. decltype
refers only to its operand's type, not its value.
decltype(void())
只是引用类型void
的冗长方式.
decltype(void())
is simply a verbose way of referring to the type void
.
这篇关于decltype(void())中的void()到底是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!