I\'m inclined to write if statements by using logical negation operator:
if (!p)
some_code();
Some people around me tend to use explicit co
One as-yet-unmentioned benefit to the if (!Foo)
version is that it will work with classes that used the safe bool idiom. In classes that implement that, comparison operators of classes will fail (e.g. Foo==0
will be undefined) but !Foo
will call a conversion operator on Foo, returning a pointer to member function (or null pointer, if Foo
should be treated as false). A number of Boost classes, like shared_ptr, use this technique.