fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. template <typename ELEM>
  6. ostream& operator << (ostream &out, const vector<ELEM> &vec)
  7. {
  8. const char *sep = "{ ";
  9. for (const ELEM &elem : vec) { out << sep << elem; sep = ", "; }
  10. return out << " }";
  11. }
  12.  
  13. int main()
  14. {
  15. vector<double> v1{ 1.0, 2.0, 3.0 }, v2{ 4.0, 5.0, 6.0 };
  16. // in one line:
  17. vector<decltype(v1.front() * v2.front())> v3 { v1[0] * v2[0], v1[0] * v2[1], v1[0] * v2[2], v1[1] * v2[0], v1[1] * v2[1], v1[1] * v2[2], v1[2] * v2[0], v1[2] * v2[1], v1[2] * v2[2] };
  18. // output:
  19. cout << v3 << endl;
  20. // done
  21. return 0;
  22. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
{ 4, 5, 6, 8, 10, 12, 12, 15, 18 }