decltype(void())中的void()到底是什么意思? [英] What does the void() in decltype(void()) mean exactly?

查看:132
本文介绍了decltype(void())中的void()到底是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是这个问题的跟进,更确切地说是评论的答案.

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(), where T 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 the void() 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆