#include <iostream>
#include <array>
#include <algorithm>
template <typename T> struct summatory
{
summatory() : result(T()) {}
void operator()(const T& value) { result += value; std::cout << value << "; "; };
T result;
};
int main(int argc, char **argv)
{
std::array<int, 10> a {{ 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 }};
summatory<int> sum;
std::cout << "\nThe summation of: ";
std::for_each(a.begin(), a.end(), sum);
std::cout << "is: " << sum.result;
std::cout << "\nThe summation of: ";
sum = std::for_each(a.begin(), a.end(), sum);
std::cout << "is: " << sum.result;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YXJyYXk+CiNpbmNsdWRlIDxhbGdvcml0aG0+Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgVD4gc3RydWN0IHN1bW1hdG9yeQp7CiAgICBzdW1tYXRvcnkoKSA6IHJlc3VsdChUKCkpIHt9CiAgICB2b2lkIG9wZXJhdG9yKCkoY29uc3QgVCYgdmFsdWUpIHsgcmVzdWx0ICs9IHZhbHVlOyBzdGQ6OmNvdXQgPDwgdmFsdWUgPDwgIjsgIjsgfTsKICAgIFQgcmVzdWx0Owp9OwoKaW50IG1haW4oaW50IGFyZ2MsIGNoYXIgKiphcmd2KQp7CiAgICBzdGQ6OmFycmF5PGludCwgMTA+IGEge3sgMSwgMSwgMiwgMywgNSwgOCwgMTMsIDIxLCAzNCwgNTUgfX07CiAgICBzdW1tYXRvcnk8aW50PiBzdW07CgogICAgc3RkOjpjb3V0IDw8ICJcblRoZSBzdW1tYXRpb24gb2Y6ICI7CiAgICBzdGQ6OmZvcl9lYWNoKGEuYmVnaW4oKSwgYS5lbmQoKSwgc3VtKTsKICAgIHN0ZDo6Y291dCA8PCAiaXM6ICIgPDwgc3VtLnJlc3VsdDsKCiAgICBzdGQ6OmNvdXQgPDwgIlxuVGhlIHN1bW1hdGlvbiBvZjogIjsKICAgIHN1bSA9IHN0ZDo6Zm9yX2VhY2goYS5iZWdpbigpLCBhLmVuZCgpLCBzdW0pOwogICAgc3RkOjpjb3V0IDw8ICJpczogIiA8PCBzdW0ucmVzdWx0Owp9