fork(2) download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <set>
  5. using namespace std;
  6.  
  7. class A {
  8. int a;
  9. public:
  10. A(int a) : a(a) {}
  11. int getA() const { return a; }
  12. void setA(int a) { this->a = a; }
  13. bool operator<(const A & b) const { return a<b.a; }
  14. };
  15.  
  16. struct myprinter {
  17. void operator()(const A & a) { cout << a.getA() << ", "; }
  18. };
  19.  
  20. struct doubler {
  21. void operator()(A& a) { a.setA(a.getA()*2); }
  22. };
  23.  
  24. int main() {
  25. int mynumbers[] = {8, 9, 7, 6, 4, 1};
  26. vector<A> s1(mynumbers, mynumbers+6);
  27. std::sort(s1.begin(), s1.end());
  28. for_each(s1.begin(), s1.end(), doubler());
  29. for_each(s1.begin(), s1.end(), myprinter());
  30. return 0;
  31. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
2, 8, 12, 14, 16, 18,