#include <iostream>
#include <algorithm>
using namespace std;
template < typename T >
struct accumulate
{
T sum;
accumulate() : sum() { }
accumulate( accumulate&& other ) : sum(other.sum)
{ cout << "r-value" << endl; }
void operator()( T const & value ) {
sum += value;
}
};
int main() {
vector<int> values = { 1, 2, 3, 4 };
auto result = for_each( values.begin(), values.end(),
::accumulate<int>() );
cout << result.sum << endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgogCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKdGVtcGxhdGUgPCB0eXBlbmFtZSBUID4Kc3RydWN0IGFjY3VtdWxhdGUKewogICBUIHN1bTsKIAogICBhY2N1bXVsYXRlKCkgOiBzdW0oKSB7IH0KICAgYWNjdW11bGF0ZSggYWNjdW11bGF0ZSYmIG90aGVyICkgOiBzdW0ob3RoZXIuc3VtKSAKICAgeyBjb3V0IDw8ICJyLXZhbHVlIiA8PCBlbmRsOyB9CiAgIAogICB2b2lkIG9wZXJhdG9yKCkoIFQgY29uc3QgJiB2YWx1ZSApIHsKICAgICAgc3VtICs9IHZhbHVlOyAgICAgIAogICB9Cn07CiAKaW50IG1haW4oKSB7CiAKICAgdmVjdG9yPGludD4gdmFsdWVzID0geyAxLCAyLCAzLCA0IH07CiAgIGF1dG8gcmVzdWx0ID0gZm9yX2VhY2goIHZhbHVlcy5iZWdpbigpLCB2YWx1ZXMuZW5kKCksIAogICAgICAgICAgICAgICAgICAgICAgICAgICA6OmFjY3VtdWxhdGU8aW50PigpICk7CiAgIGNvdXQgPDwgcmVzdWx0LnN1bSA8PCBlbmRsOwp9