jeudi 5 mars 2020

Easy way to iterate over two structures consecutively with a foreach loop

Is there an easy way to achieve this design pattern in c++17?

std::set<uint32_t> first;
std::set<uint32_t> second;

for (uint32_t number : JoinIterator<uint32_t>(first, second)) {
   <DO SOMETHING WITH number>
}

This would replace the following code:

std::set<uint32_t> first;
std::set<uint32_t> second;

for (uint32_t number : first) {
   <DO SOMETHING WITH number>
}

for (uint32_t number : second) {
   <DO SOMETHING WITH number>
}

All of the search results I have found are about looping over both structures in parallel, not looping over the structures consecutively.

Aucun commentaire:

Enregistrer un commentaire