#include <iostream>
#include <functional>
struct Data {
size_t d_size;
double *d_data;
Data(size_t size) : d_size(size), d_data(new double[size]) {}
~Data() { delete[] d_data; }
double &operator[](size_t i) { return d_data[i]; }
template<typename Lambda>
inline void forEach(Lambda f) {
for (size_t index = 0; index != d_size; ++index)
f(*this, index);
}
};
int main() {
Data im(50000000);
im.forEach([](Data &im, size_t i) {
im[i] = static_cast<double>(i);
});
double sum = 0;
im.forEach([&sum](Data &im, size_t i) {
sum += im[i];
});
std::cout << sum << '\n';
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KCnN0cnVjdCBEYXRhIHsKICBzaXplX3QgZF9zaXplOwogIGRvdWJsZSAqZF9kYXRhOwogIERhdGEoc2l6ZV90IHNpemUpIDogZF9zaXplKHNpemUpLCBkX2RhdGEobmV3IGRvdWJsZVtzaXplXSkge30KICB+RGF0YSgpIHsgZGVsZXRlW10gZF9kYXRhOyB9CiAgZG91YmxlICZvcGVyYXRvcltdKHNpemVfdCBpKSB7IHJldHVybiBkX2RhdGFbaV07IH0KICAKICB0ZW1wbGF0ZTx0eXBlbmFtZSBMYW1iZGE+CiAgaW5saW5lIHZvaWQgZm9yRWFjaChMYW1iZGEgZikgewogICAgZm9yIChzaXplX3QgaW5kZXggPSAwOyBpbmRleCAhPSBkX3NpemU7ICsraW5kZXgpCiAgICAgIGYoKnRoaXMsIGluZGV4KTsKICB9Cn07CgoKCmludCBtYWluKCkgewogIERhdGEgaW0oNTAwMDAwMDApOwogIGltLmZvckVhY2goW10oRGF0YSAmaW0sIHNpemVfdCBpKSB7CiAgICBpbVtpXSA9IHN0YXRpY19jYXN0PGRvdWJsZT4oaSk7CiAgfSk7CiAgCiAgZG91YmxlIHN1bSA9IDA7CiAgaW0uZm9yRWFjaChbJnN1bV0oRGF0YSAmaW0sIHNpemVfdCBpKSB7CiAgICBzdW0gKz0gaW1baV07CiAgfSk7CiAgCiAgc3RkOjpjb3V0IDw8IHN1bSA8PCAnXG4nOwp9