fork download
  1. #include <algorithm>
  2. #include <cassert>
  3. #include <iostream>
  4. #include <iterator>
  5. #include <vector>
  6.  
  7. void multiplyVectors(std::vector<float> &v1, std::vector<float> &v2)
  8. {
  9. assert(v1.size() <= v2.size());
  10.  
  11. std::transform(v1.begin(), // start of first input range
  12. v1.end(), // end of first input range
  13. v2.begin(), // start of **second input** range
  14. v2.begin(), // start of **output** range
  15. std::multiplies<float>());
  16. }
  17.  
  18. int main()
  19. {
  20. std::vector<float> v1{1.0, 2.0, 3.0};
  21. std::vector<float> v2{1.0, 2.0, 3.0};
  22.  
  23. multiplyVectors(v1, v2);
  24. std::copy(std::begin(v2), std::end(v2),
  25. std::ostream_iterator<float>(std::cout, "\n"));
  26. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1
4
9