Multi-action Ternar operator
-
How do you do a few things in the thermal operator? So how do you write something like that?
-
There's a comma operator, in terms.
a, b, c
All values will be computed, the latter returned. Thernar operator may use:a = cond ? (foo += 1, baz += bar, baz) : (qwe(), asd(foo, bar), zxc[baz]);
Just take into account that this accommodation is not radically different from the recording of several transactions in one line:
if (cond) { foo += 1; baz += bar; a = baz; } else { qwe(); asd(foo, bar); a = zxc[baz]; }
In fact, in order to save one assignment somewhere at the end of the blocks, you'll turn the code into a little mesivo. You can try to get more human:
a = cond ? (foo += 1, baz += bar, baz) : (qwe(), asd(foo, bar), zxc[baz]);
or even so:
a = cond ? ( foo += 1, baz += bar, baz ) : ( qwe(), asd(foo, bar), zxc[baz] );
But then all the advantages of the thermal operator are lost in the form of exhilaration. Anyway, if you don't work on a code for fuscation competition. http://www.ioccc.org/ or you don't want to throw knowledge in front of your buddies, that code should be avoided.