fork download
  1. #include <vector>
  2. #include <iostream>
  3. #include <cassert>
  4.  
  5. template <typename T>
  6. const std::vector<T> operator+(const std::vector<T>& lhs, const std::vector<T>& rhs)
  7. {
  8. assert(lhs.size() == rhs.size());
  9. std::vector<T> r(lhs.size());
  10.  
  11. for (std::size_t i = 0; i < lhs.size(); ++i)
  12. {
  13. r[i] = lhs[i] + rhs[i];
  14. }
  15.  
  16. return r;
  17. }
  18.  
  19. int main()
  20. {
  21. std::vector<int> a;
  22. a.push_back(1);
  23. a.push_back(2);
  24. a.push_back(3);
  25.  
  26. std::vector<int> b;
  27. b.push_back(11);
  28. b.push_back(12);
  29. b.push_back(13);
  30.  
  31. std::vector<int> c = a + b;
  32.  
  33. for (std::size_t i = 0; i < c.size(); ++i)
  34. {
  35. std::cout << c[i] << '\n';
  36. }
  37. }
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
12
14
16