Pretty sure "!" has higher precedence than "==", so that !vec.size() == 0 is not the same thing as !(vec.size() == 0) if that is so, what's going to happen here is that the result of the call to size(), probably an unsigned integral type, will be converted to a boolean, either true or false, that answer will be logically inverted, promoted to an int, and compared to 0, for equality. Below, res is the value of the expression. Imagine:
1 2 3 4 5
size_t len = vec.size();
bool b = (bool) len;
bool nb = !b;
int ilen = (int) nb;
bool res = ilen == 0;
My opinion would be to avoid constructs like this, that convert an integer to a boolean to then compare it with an integer. I think it looks confusing and it's hard to tell it apart from a typo.
I think I would use either if ( !vec.empty() )
or if ( vec.size() )
instead
This makes much more sense.
(Personally I'd even be more explicit in that last one, and do if (vec.size() > 0))
I agree, simplify and clarify. first, the original expression does 2 things (a not and a compare) so it is wasteful, and second, it does 2 things when 1 is all that is required, making it convoluted to read and unclear as to intent.