5

I was wondering whether … was considered an operator in C++11. And if it’s the case, what’s its precedence?

For instance consider this pretty bad example and assume ... is an operator.

template<typename T, typename...Args>
void foo(T _elm, Args... _args)
{
   bar(something,_args...);
}

How can I know whether bar will be run with its first parameter being something and args... expanded, or if its gonna be run on the result of operator,(something, _args...) ? (bonus question: can operators be overloaded with variadic templates ?)

qdii
  • 12,505
  • 10
  • 59
  • 116
  • 1
    "can operators be overloaded with variadic templates" No. Or at least, you wouldn't get anything by doing it. Operators always take a specific number of parameters. – Nicol Bolas Mar 10 '12 at 17:39
  • See [this](http://stackoverflow.com/questions/2396065/c-overloading-operator-comma-for-variadic-arguments). – ApprenticeHacker Mar 10 '12 at 17:39
  • 2
    @Nicol `operetor()` can take as many arguments as you want it to. –  Mar 10 '12 at 18:40

1 Answers1

4

I was wondering whether … was considered an operator in C++11

No, ... is definitely not considered an operator in C++ 11. If you remember, it was also used in the previous standard in error handling

catch(...)

and though I am not sure how the ... is analysed and parsed internally, it is definitely not treated as an operator.

Can operators be overloaded with variadic templates ?

I'm not sure, but I don't think so. Operators have to take a specified set of parameters like:

int operator + (int param1, my_obj param2);

I don't think it would work with variadic templates.

ApprenticeHacker
  • 21,351
  • 27
  • 103
  • 153