fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. template < typename T >
  7. struct accumulate
  8. {
  9. T sum;
  10.  
  11. accumulate() : sum() { }
  12. accumulate( accumulate&& other ) : sum(other.sum)
  13. { cout << "r-value" << endl; }
  14.  
  15. void operator()( T const & value ) {
  16. sum += value;
  17. }
  18. };
  19.  
  20. int main() {
  21.  
  22. vector<int> values = { 1, 2, 3, 4 };
  23. auto result = for_each( values.begin(), values.end(),
  24. ::accumulate<int>() );
  25. cout << result.sum << endl;
  26. }
Success #stdin #stdout 0s 3016KB
stdin
Standard input is empty
stdout
r-value
10