Can I write a range based for loop in c++ with two parallel iterators
I have code like this -
class Result{
...
...
};
std::vector<Result> results;
std::vector<Result> groundTruth(2);
int gtIndex = 0;
for(auto& r:results){
auto gt = groundTruth[gtIndex];
// compare r and gt
gtIndex++;
}
I access elements from the groundTruth using gtIndex.
Question : How do I include the ground truth iterator in the range based for loop in C++.
In python I am aware of zip function which does this, but could not find anything like that in C++.
I do not know any easy way to get what you want, however, you can get halfway there by using a reference to the elements of groundTruth instead array indexing.
First, you may want to verify sizes:
Then you can run your loop with just two or three extra lines of boilerplate (two if you do not need to check sizes):