|
> Overloading the Comma Operator Is Powerful Clearly, it's over 9000! ... more seriously though, overloading the comma operator is a bad idea and you shouldn't do it. In fact, almost nobody does it. Specifically, you don't want to break the principle of least astonishment with a command such as v+= 1,2,3,4,5;
Assuming you want to add up a bunch of literals, what you could do is something like: std::array data { 1,2,3,4,5 };
v += std::reduce(data.begin(), data.end());
and if you've implemented some <algorithm> and <numeric> wrappers for containers, you would have something like an template<class Container>
typename Container::value_type
reduce(const Container& container);
and then you would write v += reduce(std::array{ 1,2,3,4,5 } );
which is terse and much clearer. |