The code below shows how to iterate through a vector of vectors.
const size_t quantity_vectors(vectors.size());
for (size_t i = 0; i < quantity_vectors; ++i)
{
const std::vector<int>& vector_a(vectors[i]);
const std::vector<int>& other_vector(vectors[(i + 1) % quantity_vectors]);
const size_t quantity_a_vector(vector_a.size());
for (size_t j = 0; j < quantity_a_vector; ++j)
{
// do something
// example: std::find(other_vector.begin(), other_vector.end(), vector_a[j]);
}
}
The expression vectors[i]
returns a std::vector
.
I'm using a reference to avoid making copies.
The reference is const
because I'm not changing anything inside the vectors.