(For a specific compiler / platform context, take GCC 4.7 and Ubuntu 12.04 on x86_64)
For some function f:
void f(int x, int y);
int nx = ...;
int ny = ...;
One way to iterate over each value of (x, y) from (0,0) to (nx, ny):
for (int x = 0; x < nx; x++)
for (int y = 0; y < ny; y++)
f(x,y);
Let this compile with some generated Q1 code.
We will write a function g such that:
for (auto it : g(Z))
f(it.x, it.y);
compiled Q2 code.
Can g be written so that Q2 is as efficient as Q1? If so, how? If not, then the closer we can get?
You can change auto to auto & or auto && if that helps.
You can also change it.x to it.x () and it.y to it.y () if that helps.
(, , : ++ 11: : " range- init " ?)