fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. class x {
  6. int n;
  7. public:
  8. x(int n) { this->n = n; }
  9. void operator()(int v) { std::cout << n << " : " << v << std::endl; }
  10. };
  11.  
  12. int const n = 10;
  13. int main() {
  14. x a(10), b(100);
  15. std::vector<int> v;
  16. for (int i = 0; i < n; i++) v.push_back(i);
  17. std::for_each(v.begin(), v.end(), a);
  18. std::for_each(v.begin(), v.end(), b);
  19. return 0;
  20. }
  21. /* end */
  22.  
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
10 : 0
10 : 1
10 : 2
10 : 3
10 : 4
10 : 5
10 : 6
10 : 7
10 : 8
10 : 9
100 : 0
100 : 1
100 : 2
100 : 3
100 : 4
100 : 5
100 : 6
100 : 7
100 : 8
100 : 9