#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;
}