#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
template<typename T>
struct list {
vector<T> data;
template<typename F>
list<T> filter(F f) const {
vector<T> result;
copy_if(begin(data), end(data), back_inserter(result), f);
return { result };
}
template<typename F>
list<T> map(F f) const {
vector<T> result(data.size());
transform(begin(data), end(data), begin(result), f);
return { result };
}
template<typename F>
void each(F f) const {
for_each(begin(data), end(data), f);
}
};
int main() {
(list<int>{{ 1, 2, 3, 4, 5, 6, 2016 }})
.filter([](auto x){ return x % 2; })
.map([](auto x){ return x*x; })
.each([](auto x){ cout << x << " "; });
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8aXRlcmF0b3I+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBUPgpzdHJ1Y3QgbGlzdCB7Cgl2ZWN0b3I8VD4gZGF0YTsKCQoJdGVtcGxhdGU8dHlwZW5hbWUgRj4KCWxpc3Q8VD4gZmlsdGVyKEYgZikgY29uc3QgewoJCXZlY3RvcjxUPiByZXN1bHQ7CgkJY29weV9pZihiZWdpbihkYXRhKSwgZW5kKGRhdGEpLCBiYWNrX2luc2VydGVyKHJlc3VsdCksIGYpOwoJCXJldHVybiB7IHJlc3VsdCB9OwoJfQoJCgl0ZW1wbGF0ZTx0eXBlbmFtZSBGPgoJbGlzdDxUPiBtYXAoRiBmKSBjb25zdCB7CgkJdmVjdG9yPFQ+IHJlc3VsdChkYXRhLnNpemUoKSk7CgkJdHJhbnNmb3JtKGJlZ2luKGRhdGEpLCBlbmQoZGF0YSksIGJlZ2luKHJlc3VsdCksIGYpOwoJCXJldHVybiB7IHJlc3VsdCB9OwoJfQoJCgl0ZW1wbGF0ZTx0eXBlbmFtZSBGPgoJdm9pZCBlYWNoKEYgZikgY29uc3QgewoJCWZvcl9lYWNoKGJlZ2luKGRhdGEp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