谈一谈c++中的unevaluated operand

什么是unevaluated operand

我们先看2段外文:

In some contexts, unevaluated operands appear (5.2.8, 5.3.3, 5.3.7, 7.1.6.2). An unevaluated operand is not evaluated. An unevaluated operand is considered a full-expression. [ Note: In an unevaluated operand, a non-static class member may be named (5.1) and naming of objects or functions does not, by itself, require that a definition be provided (3.2). —end note ]
+ 5.2.8 covers typeid
+ 5.3.3 covers sizeof
+ 5.3.7 covers noexcep
+ 7.1.6.2 covers simple type specifiers such as auto and decltype and POD types like int, char, double etc.

The operands of the four operators typeid, sizeof, noexcept, and decltype (since C++11) are expressions that are not evaluated (unless they are polymorphic glvalues and are the operands of typeid), since these operators only query the compile-time properties of their operands. Thus, std::size_t n = sizeof(std::cout << 42); does not perform console output.
The unevaluated operands are considered to be full expressions even though they are syntactically operands in a larger expression (for example, this means that sizeof(T()) requires an accessible T::~T)

可以这样理解:
1. unevaluated operand是不被评估的,它是一个完整的表达式。c++中4个操作符typeid,sizeof, noexcept,decltype对应的表达式是不需要被评估的。
2. unevaluated operand仅仅是查询编译期间的相关属性,并不会生产运行期的代码。
3. unevaluated operand不会去完全编译表达式,即不会完全检查编译的错误,但是参数值和需要推导返回值的地方会执行编译检查。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值