On Tuesday, 25 March 2014 at 14:00:28 UTC, Byron wrote:
On Sun, 23 Mar 2014 20:09:45 -0700, Andrei Alexandrescu wrote:
That was in Phobos too. Fix:
int a = something == 1 ? 1
: something == 2 ? 2 : { assert(0); return 0; }();
There are of course other ways, too, including defining a
function that
returns its last argument.
Andrei
This would be a red flag in my code review, nested ternaries
are to hard
to read and even worse for maintainability. Been bit to many
times with
little bugs in them. Wish compilers would throw a warning when
they are
used.
We use chained ternaries in our code regularly, and had no
problem with them, with more than average programmers on the
project. In my experience syntax didn't cause a single bug.