fork download
  1. #include <vector>
  2. #include <iterator>
  3. #include <algorithm>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. const int spaceSize = 10;
  9.  
  10. void Negate(vector<double>& x, vector<double>& y)
  11. {
  12. // transform(x.begin(), x.end(), back_inserter(y), negate<double>());
  13. transform(x.begin(), x.end(), y.begin(), negate<double>());
  14. }
  15.  
  16.  
  17. int main()
  18. {
  19. vector<double> one, two;
  20. for(int i = 0; i < spaceSize; i++)
  21. {
  22. one.push_back(2.0 * i);
  23. two.push_back(1.0 * i);
  24. }
  25.  
  26. Negate(one, two);
  27.  
  28. copy(two.begin(), two.end(), ostream_iterator<int>(cout, "\n"));
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 2856KB
stdin
Standard input is empty
stdout
0
-2
-4
-6
-8
-10
-12
-14
-16
-18