Advertisement
wowonline

Untitled

Mar 19th, 2022
740
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <vector>
  2. #include <iostream>
  3. #include <cstdint>
  4. #include <algorithm>
  5.  
  6. class Accum {
  7.     public:
  8.         int sum;
  9.         Accum(int s) {
  10.             sum = s;
  11.         }
  12.  
  13.         void operator() (int &value) {
  14.             sum += value;
  15.             std::cout << sum << std::endl;
  16.         }
  17. };
  18.  
  19. int main()
  20. {
  21.     std::vector <int> v{1, 2, 3, 4, 5};
  22.  
  23.     Accum inst(0);
  24.     std::for_each(v.begin(), v.end(), inst);
  25.     std::cout << inst.sum << std::endl;
  26. }
Advertisement
RAW Paste Data Copied
Advertisement