When iterating over a std::vector, I've always declared the index variable to be of size_type as in
std::vector<someReallyLengthy<TypeWith,SubTypes>> a(5);
for (std::vector<someReallyLengthy<TypeWith,SubTypes>>::size_type k = 0; k < a.size(); k++) {
// do something with a[k]
}
I'm wondering if in C++11 (or later) there's a shorthand-notation for the size_type here.
(auto won't work since it can't deduct from 0 which type it targets.)
Aucun commentaire:
Enregistrer un commentaire