The short answer (as everyone in the comments say) is "right, thatβs pointless." I also found this annoying. Depending on your programming style, you might like the "zipfor" package I wrote (just the title): from github
It allows you to use the syntax as
std::vector v; zipfor(x,i eachin v, icounter) { // use x as deferenced element of x // and i as index }
Unfortunately, I cannot figure out how to use range-based syntax and resort to the zipfor macro :(
The headline was originally intended for things like
std::vector v,w; zipfor(x,y eachin v,w) { // x is element of v // y is element of w (both iterated in parallel) }
and
std::map m; mapfor(k,v eachin m) // k is key and v is value of pair in m
My g ++ 4.8 tests with full optimization show that the resulting code is no slower than writing it manually.
source share