Daily DRY tip
Hello, back again with the daily, erm, monthly DRY tip.
Again, a short piece of C++ code.
if( bBool ) a = some_constant ; else b = some_constant ;
Auwch, such repeatingness is almost unbearable to even glance at.
To the rescue, our dear friend the ternary operator.
( bBool ? a : b ) = some_constant ;
The brackets are there so the ternary operator does not get confused and tries to evaluate b = some_constant as one of the parts of the ternary expression.
Entry filed under: Command Line.