负责解压模板类型参数包的元运算符 ...
的优先级是什么?我认为这个数字相当低,但到底低到什么程度呢? C++ 标准说:
运算符的优先级不是直接指定的,但可以从语法中得出。
有人愿意接受挑战吗?当然,...
不会出现在C++03运算符优先级表中。
好的,如果 ...
不是运算符,那么究竟是什么决定了 std::forward(args)...
适用于整个序列 std::forward(args) 而不仅仅是 (args)
?
What is the precedence of the meta-operator ...
whose job is to unpack template type parameter packs? I imagine it's pretty low, but how low is it? The C++ standard says:
The precedence of operators is not directly specified, but it can be derived from the syntax.
Anyone up for the challenge? Of course, ...
does not appear in C++03 operator precedence tables.
Okay, if ...
is not an operator, what exactly determines that std::forward<Args>(args)...
applies to the the entire sequence std::forward<Args>(args)
and not just (args)
, for example?
发布评论
评论(2)
看来不是运营商啊来自 N3092(抱歉我手边没有更新的草稿)
It doesn't seem to be an operator. From N3092 (sorry I don't have a more recent draft handy)
根据方便的 超链接 C++ BNF 语法,函数调用如下所示:
expression-list 只是一个 初始化列表,如下所示:
其中省略号是包扩展符号。
反过来,初始化子句可以是赋值-表达式或braced-init-list。
所有这一切都是说,省略号的语法优先级低于任何实际运算符,因此例如以下内容是等效的:
According to the handy Hyperlinked C++ BNF Grammar, a function call looks like this:
expression-list is just an initializer-list, which looks like this:
where the ellipses are the pack expansion notation.
initializer-clause, in turn, can be either assignment-expression or braced-init-list.
All this is to say, then, that the ellipsis has a lower grammatical precedence than any actual operator, so for instance the following are equivalent: