Although you can write code like this, it can be somewhat strange. A slightly more realistic usecase would be if you have a T structure as follows:
struct T { bool check() const; void fix(); };
Now you want to iterate over everything in the structure and run a check on it, and then call fix if check returns false. An easy way to do this would be
for (list<T>::iterator it = mylist.begin(); it < mylist.end(); ++it) if (!it->check()) it->fix();
Suppose you want to record it as short as possible. fix() return void means you cannot just put it in a state. However, using a comma, you can get around this:
for (auto it = mylist.begin(); it != mylist.end() && (it->check() || (it->fix(), true)); ++it);
I would not use it without much reason, but this allows you to call any function from a condition that may be convenient.
Anton Golov
source share