Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the precedence of the meta-operator ...?

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?

like image 853
fredoverflow Avatar asked Aug 12 '11 15:08

fredoverflow


1 Answers

It doesn't seem to be an operator. From N3092 (sorry I don't have a more recent draft handy)

[14.5.3] 4/ A pack expansion is a sequence of tokens that names one or more parameter packs, followed by an ellipsis. The sequence of tokens is called the pattern of the expansion; its syntax depends on the context in which the expansion occurs. Pack expansions can occur in the following contexts:

  • In an initializer-list (8.5); the pattern is an initializer-clause.
  • In a base-specifier-list (10); the pattern is a base-specifier.
  • In a mem-initializer-list (12.6.2); the pattern is a mem-initializer.
  • In a template-argument-list (14.3); the pattern is a template-argument.
  • In a dynamic-exception-specification (15.4); the pattern is a type-id.
  • In an attribute-list (7.6.1); the pattern is an attribute.
  • In a capture-list (5.1.2); the pattern is a capture. [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 example]

like image 180
Alexandre C. Avatar answered Nov 17 '22 06:11

Alexandre C.