Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C++11, is … considered an operator?

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 ?)

like image 407
qdii Avatar asked Oct 08 '22 10:10

qdii


1 Answers

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.

like image 185
ApprenticeHacker Avatar answered Oct 12 '22 11:10

ApprenticeHacker