FWIW, !! is a fairly idiomatic way to cast a value to bool.
int countNonZero = 0;
for (int i = 0; i < values.size(); ++i) {
countNonZero += !!values[i];
}
Also c++ has explicit operator bool();edit: not a great example as values[1] >0 would be better.
The reason I'm pointing this out is that often enough I had to work with code where this distinction was unknown to the author and you come across code like if (!!x) which is, again, just nonsense.
Only if that's an array of unsigned ints, as otherwise the code would count only positive nonzeros.