std::vector<int> vec;
// test for sorted..
bool sorted = true;
for (size_t i = 0; i < vec.size() - 1ULL; ++i)
if (vec[i] > vec[i+1]) {
sorted = false;
break;
}
I believe the google c++ style guide rues the selection of unsigned integers as the return type of size() in the standard library for reasons like the above. Personally, my preferred behavior would be to have a compiler flag that could be used to enable a trap if unsigned arithmetic resulted in wrap-around, as in the above case when the vector is of length zero.