Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <iterator>
  4.  
  5. struct S
  6. {
  7. int sum = 0;
  8. void operator()(int i) { sum += i; }
  9. };
  10.  
  11. int main(void) {
  12. int a[] = { 1, 2, 3, 4, 5 };
  13. std::cout << std::for_each(std::begin(a), std::end(a), S()).sum << std::endl;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement