how to loop in sync over 2 maps? it could be that either map1 or map2 contains more keys. how do i set the preference? and increment the corresponding iterator?
example values of 2 maps:
4 7 10 11 12 13 14
3 4 7 8 10 11 12 13 14
What's the best way to iterate over two or more containers simultaneously
std::map<int, int> map1;
std::map<int, int> map2;
auto itA = begin(map1);
auto itB = begin(map2);
while(itA != end(map1) || itB != end(map2))
{
if(itA != end(map1))
{
++itA;
}
if(itB != end(map2))
{
++itB;
}
}
Read more here: https://stackoverflow.com/questions/65002494/how-to-keep-in-sync-looping-over-2-maps
Content Attribution
This content was originally published by NaturalDemon at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.