[当有人询问decltype(a)
和decltype((a))
之间的差异时,通常的答案是-a
是变量,(a)
是表达式。我觉得这个答案不令人满意。
首先,a
也是一个表达式。 primary expression的选项包括->
更重要的是,decltype considers parentheses very, very explicitly的措词:
括号的区别?是否有人熟悉其背后的技术论文或委员会讨论?括号的明确考虑导致认为这不是疏忽,所以一定有我所缺少的技术原因。For an expression e, the type denoted by decltype(e) is defined as follows: (1.1) if e is an unparenthesized id-expression naming a structured binding, ... (1.2) otherwise, if e is an unparenthesized id-expression naming a non-type template-parameter, ... (1.3) otherwise, if e is an unparenthesized id-expression or an unparenthesized class member access, ... (1.4) otherwise, ...
所以问题仍然存在。 为什么
之前已经讨论过该主题,但这不是重复的。当有人问decltype(a)和decltype((a))之间的区别时,通常的回答是-a是变量,(a)是...
为什么括号要区别对待?
Decltype and auto(revision 4)(N1705 = 04-0145)