Just that wrote:
Q: 1> if (M_only) do_abc
else do_xyz
2> (M_only)?do_abc:do_xyz;
supplementary question: in case the if-then structure gets more
complicated, between readability and speed which one would be
preferred and in what stage ? Be as clear as you can.
A:
Generally speaking, one form is not faster than the other. I prefer to
use form 2 in assignments and for return values:
int messageType = (d_useOldMessagesFlag)
? MessageTypes::TYPE1
: MessageTypes::TYPE2;
or
return (stream) ? 0 : -1;
However, if you find yourself using the ?: operator a lot, you should
consider whether your design is too general. For example, a method like
'processMessage' that has a lot of branches in it for handling new and
old messages might be better served by two methods, 'processNewMessage'
and 'processOldMessage', or by a virtual function.
/david