fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iterator>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. struct Vector3 { float x, y, z; };
  9.  
  10. struct Mesh {
  11. vector<Vector3> positions;
  12. vector<int> indices;
  13. };
  14.  
  15. ostream& operator<<(ostream& os, const Mesh& m) {
  16. for (const auto& pos : m.positions) cout << "(" << pos.x << ", " << pos.y << ", " << pos.z << "), ";
  17. for (const auto& index : m.indices) cout << index << ", ";
  18. cout << endl;
  19. return os;
  20. }
  21.  
  22. int main() {
  23. // initialize a Mesh with explicit verts and indices
  24. Mesh myMesh { { { 0.f, 0.f, 0.f }, { 1.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f } },
  25. { 0, 1, 2 } };
  26.  
  27. // initialize a Mesh with iterator pairs
  28. Mesh mySecondMesh { { begin(myMesh.positions), end(myMesh.positions) },
  29. { begin(myMesh.indices), end(myMesh.indices) } };
  30.  
  31. // initialize a Mesh as a copy of an existing mesh
  32. Mesh myThirdMesh = myMesh;
  33.  
  34. cout << myMesh << mySecondMesh << myThirdMesh;
  35. }
  36.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
(0, 0, 0), (1, 0, 0), (0, 1, 0), 0, 1, 2, 
(0, 0, 0), (1, 0, 0), (0, 1, 0), 0, 1, 2, 
(0, 0, 0), (1, 0, 0), (0, 1, 0), 0, 1, 2,