Try entering an auxiliary function as follows:
template <typename T> T zeroIfLess(T val, T base) { return val < base ? T(0) : val; }
Then write your condition as:
if (WORD wNotifyCode = zeroIfLess(HIWORD(wparam), 2))
This returns zero β or, if you wish, false β if the first value supplied is less than the second; otherwise, it returns a value. Given that it is difficult to determine the meaning of a function name and whether to use the inclusive or exclusive minimum that it works here, this does not reduce it, as a strange hack.
Like others, I also approve of your first sentence after "And You Can Do It" - a separate expression and an initialization expression, followed by a conditional statement. I think this is a natural way to do this in C ++.
source share