Reputation: 433
Is it still valid and good practice in C++11 write if clause like
int i;
//some code
if (i) //some code
or it is preferred to write
if(i != 0)
Upvotes: 3
Views: 253
Reputation: 39390
It is well-defined behaviour, so you can use the shorter expression. It might seem cryptic for a non-experienced developer, but regulars shouldn't have problems in understanding it.
It might have some sense to use the longer form when explicitly treating i
as a number, and omitting it when it has some other logical meaning.
Upvotes: 4
Reputation: 5724
It is valid to use integral POD types as a conditional expression.
I do not think there are any requirements in C++11 to use one style over the other.
Thus, choose whichever style you prefer.
Upvotes: 0