fork download
  1. #include <vector>
  2.  
  3. #include <iostream>
  4.  
  5. #include <algorithm>
  6.  
  7. #include <functional>
  8.  
  9. using namespace std;
  10.  
  11. class Pocket
  12. {
  13.  
  14. int value;
  15.  
  16. public:
  17.  
  18. Pocket (int value):value (value)
  19. {
  20. }
  21.  
  22. int getValue () const
  23. {
  24. return value;
  25. }
  26.  
  27. operator int () const
  28. {
  29. return value;
  30. }
  31.  
  32. bool operator < (const Pocket & _Right) const
  33. {
  34. return value < _Right.value;
  35. }
  36.  
  37. };
  38.  
  39. ostream & operator << (ostream & stream, const Pocket & pocket)
  40. {
  41.  
  42. stream << pocket.getValue ();
  43.  
  44. return stream;
  45.  
  46. }
  47. void
  48. printer (Pocket i)
  49. { // LINE I
  50.  
  51. cout << i << ", ";
  52.  
  53. }
  54.  
  55. int
  56. main ()
  57. {
  58.  
  59. Pocket mynumbers1[] = { 8, 9, 7, 6, 4, 1 };
  60.  
  61. Pocket mynumbers2[] = { 8, 9, 1, 2, 2, 1 };
  62.  
  63. vector < Pocket > v1 (mynumbers1, mynumbers1 + 6);
  64.  
  65. vector < Pocket > v2 (mynumbers2, mynumbers2 + 6);
  66.  
  67. vector < Pocket > v3 (6, 0);
  68.  
  69. transform (v1.begin (), v1.end (), v2.begin (), v3.begin (), minus < Pocket > ()); //LINE II
  70.  
  71. for_each (v1.rbegin (), v1.rend (), printer);
  72.  
  73. return 0;
  74.  
  75. }
  76.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
1, 4, 6, 7, 9, 8,