A range based loop could be a cleaner solution:
for (const auto& i : a)
{
}
Here, i
is a const
reference to an element of container a
.
Otherwise, if you need the index, or if you don’t want to loop over the entire range, you can get the type with decltype(a.size())
.
for (decltype(a.size()) i = 0; i < a.size(); ++i) {
}