fork(1) download
  1. #include <array>
  2. #include <algorithm>
  3. #include <iostream>
  4.  
  5. typedef std::array<float,3> Vector3D;
  6.  
  7. Vector3D operator + (const Vector3D& a, const Vector3D& b)
  8. {
  9. Vector3D c;
  10. std::transform(a.begin(), a.end(), b.begin(), c.begin(),
  11. [](float a, float b){return a + b;});
  12. return c;
  13. }
  14.  
  15. std::ostream& operator << (std::ostream& os, const Vector3D& a)
  16. {
  17. return os << a[0] << ',' << a[1] << ',' << a[2];
  18. }
  19.  
  20. int main() {
  21. Vector3D a = {2, 3, 0};
  22. Vector3D b = {3, -3, 0};
  23. Vector3D c = a + b;
  24. std::cout << c << std::endl;
  25. }
Success #stdin #stdout 0s 2884KB
stdin
Standard input is empty
stdout
5,0,0