What would be the best way to check that a std::vector is sorted? Is there something faster than a loop checking that v[i]<=v[i+1]? Is it faster/cleaner with iterators? Or is it actually better to just call sort every time (though the "v is already sorted" case is quite common)?
We can safely assume the vector only contains PODs, usually floats and sometimes doubles and ints.
The size of the vector is non-trivial (usually a few thousands items) but not extreme (not gigabyte-sized).
- in some instances we'll sort the vector immediately afterwards, however there are other instances where we don't (it's an error case of our algorithm).
- we already use a flag "IsSorted" whenever possible.