Comma Operator

Jan. 13, 2017, 9:11 p.m.

I saw this today:

void foo() {}
void bar() {
    bool b = (foo(), 1);

I thought the C++ standards committee sneaked in first-class tuple support under my nose, but no, that's just abusing the comma operator. Something about having a void function call on the right-hand side just rubs me the wrong way though.

The only good use of comma operator that I've seen is doing slightly more complex things in for-loop endings:

for (int i = 1, j = 2; i < 10; i++, j *= 2) {

But I also see some examples of people overloading comma for the tuple class (with some C++11 template magick) so that they can pretend there is first class support. I guess I wasn't that off after all!