What is the priority of the metaoperator ...?

What is the priority of the meta-operator ... whose task is to unpack the packages of parameters of the template type? I suppose it's pretty low, but how low is it? The C ++ standard says:

The priority of the operators is not directly specified, but it can be obtained from the syntax.

Anyone for calling? Of course ... does not appear in the priority tables of C ++ 03 operators.


Well, if ... not an operator, which determines that std::forward<Args>(args)... applies to the whole sequence std::forward<Args>(args) , and not just (args) , eg?

+7
source share
2 answers

This is not like an operator. From N3092 (Sorry, I do not have a newer project)

[14.5.3] 4 / A package extension is a sequence of tokens that names one or more parameter packages, followed by an ellipsis. The sequence of tokens is called an expansion scheme; its syntax depends on the context in which the extension occurs. Package extensions can occur in the following contexts:

  • In the list of initializers (8.5); The pattern is an initializer-item.
  • In the base-specifier-list (10); a template is a basic qualifier.
  • In the list mem-initializer (12.6.2); The template is a meme initializer.
  • In the list of argument templates (14.3); pattern is a pattern of arguments.
  • In the specification of dynamic exclusion (15.4); pattern is an identifier type.
  • In the list of attributes (7.6.1); the template is an attribute.
  • In the capture list (5.1.2); The template is a grip. [Example:

     template<class ... Types> void f(Types ... rest); template<class ... Types> void g(Types ... rest) { f(&rest ...); // "&rest ..." is a pack expansion; "&rest" is its pattern } 

    - end of example]

+5
source

According to the convenient Hyperlinked C ++ BNF Grammar function call is as follows:

postfix-expression (expression-list opt )

list-list is just an initializer-list that looks like this:

initializer-clause ... opt
initializer-list, initializer-clause ... opt

where ellipses are the designation of the package extension.

A sentence initializer, in turn, can be assignment-expression or braced-init-list .

All this means that the ellipsis has a lower grammatical priority than any real operator, therefore, for example, the following equivalents:

 foo(args ^= 0x1234...) and foo((args ^= 0x1234)...) foo(x ? args : 42...) and foo((x ? args : 42)...) 
+1
source

All Articles