I want to have the following work
std::vector<int> range{0,1,2,3};
for(std::vector<int>::iterator vit : range | iterator_range ){
int v = *vit;
}
this would be equivalent to the standard for loop
std::vector<int> range{0,1,2,3};
for(std::vector<int>::iterator vit = begin(range); vit !=end(range); vit++) ){
int v = *vit;
}
except more elegant.
iterator_range is an adapter that I require.
I have some algorithms where it is useful to require to have an iterator to the element inside the loop rather than the element itself.
Note that
views::iotais not limited to integers, it's anything that's incrementable and comparable. Which includes iterators!This at least gets you started, and maybe is good enough. Ideally you have a proper range adapter that captures
views::all(r)without requiring borrowed, and actually gives out these iterators directly.A more complete implementation (if actually necessary) would be:
Which you can see here.