I am trying to understand how C++ 11's for(type& x : ) (& stl's for_each) works internally and hoping someone can enlighten me. So the following code:
vector<int> v;
int z=0;
for (int i = 0; i < 5; ++i)
v.push_back(z++);
for (int& i : v)
{
printf(" %i", i);
v.insert(v.begin(), z++);
}
prints 0 0 1 2 3. I would understand 0 0 0 0 0 or 0 1 2 3 4, but that output, I can't quite understand how? What does for(x:y) compile to?? Don't think this will matter much, but I am using clang 3.4.
Thanks!