#include <iostream>
using namespace std;
template<int N>
void increment(int (&v)[N])
{
// No problem
int w[10] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 9 };
for (int& x : w){
std::cout << "range-for-statement: " << ++x << "\n";
}
// error: cannot build range expression with array function
// parameter 'v' since parameter with array type 'int []' is
// treated as pointer type 'int *'
for (int x : v){
std::cout << "printing " << x << "\n";
}
// No problem
for (int i = 0; i < 10; i++){
int* p = &v[i];
}
}
int main()
{
int v[10] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 9 };
increment(v);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdGVtcGxhdGU8aW50IE4+CnZvaWQgaW5jcmVtZW50KGludCAoJnYpW05dKQp7CgkvLyBObyBwcm9ibGVtCglpbnQgd1sxMF0gPSB7IDksIDgsIDcsIDYsIDUsIDQsIDMsIDIsIDEsIDkgfTsKCWZvciAoaW50JiB4IDogdyl7CgkJc3RkOjpjb3V0IDw8ICJyYW5nZS1mb3Itc3RhdGVtZW50OiAiIDw8ICsreCA8PCAiXG4iOwoJfQoKCS8vIGVycm9yOiBjYW5ub3QgYnVpbGQgcmFuZ2UgZXhwcmVzc2lvbiB3aXRoIGFycmF5IGZ1bmN0aW9uIAoJLy8gcGFyYW1ldGVyICd2JyBzaW5jZSBwYXJhbWV0ZXIgd2l0aCBhcnJheSB0eXBlICdpbnQgW10nIGlzIAoJLy8gdHJlYXRlZCBhcyBwb2ludGVyIHR5cGUgJ2ludCAqJwoJZm9yIChpbnQgeCA6IHYpewoJCXN0ZDo6Y291dCA8PCAicHJpbnRpbmcgIiA8PCB4IDw8ICJcbiI7Cgl9CgoJLy8gTm8gcHJvYmxlbQoJZm9yIChpbnQgaSA9IDA7IGkgPCAxMDsgaSsrKXsKCQlpbnQqIHAgPSAmdltpXTsKCX0KfQoKaW50IG1haW4oKQp7CglpbnQgdlsxMF0gPSB7IDksIDgsIDcsIDYsIDUsIDQsIDMsIDIsIDEsIDkgfTsKCWluY3JlbWVudCh2KTsKfQ==