#include <iostream>
#include <functional>
#include <array>
template <class T, size_t N>
void foreach(std::array<T, N> &arr, std::function<void(T&)> fun)
{
for(auto &item: arr)
{
fun(item);
}
}
int main()
{
std::array<int, 10> a = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int y = 2;
std::function<void(int&)> f = [=](int &x) { x = x * y; };
foreach(a, f);
for(const auto &item: a)
{
std::cout << item << " ";
}
std::cout << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KI2luY2x1ZGUgPGFycmF5PgoKdGVtcGxhdGUgPGNsYXNzIFQsIHNpemVfdCBOPgp2b2lkIGZvcmVhY2goc3RkOjphcnJheTxULCBOPiAmYXJyLCBzdGQ6OmZ1bmN0aW9uPHZvaWQoVCYpPiBmdW4pCnsKCWZvcihhdXRvICZpdGVtOiBhcnIpCgl7CgkJZnVuKGl0ZW0pOwoJfQp9CgppbnQgbWFpbigpCnsKICAgIHN0ZDo6YXJyYXk8aW50LCAxMD4gYSA9IHsgMCwgMSwgMiwgMywgNCwgNSwgNiwgNywgOCwgOSB9OwogICAgaW50IHkgPSAyOwoJc3RkOjpmdW5jdGlvbjx2b2lkKGludCYpPiBmID0gWz1dKGludCAmeCkgeyB4ID0geCAqIHk7IH07CiAgICBmb3JlYWNoKGEsIGYpOwogICAgZm9yKGNvbnN0IGF1dG8gJml0ZW06IGEpCiAgICB7CiAgICAgICAgc3RkOjpjb3V0IDw8IGl0ZW0gPDwgIiAiOwogICAgfQogICAgc3RkOjpjb3V0IDw8IHN0ZDo6ZW5kbDsKfQo=