fork(2) download
  1. #include <vector>
  2. #include <stdio.h>
  3.  
  4. namespace Test
  5. {
  6. struct Vector2f{float x, y;};
  7. struct Vector3f{float x, y, z;};
  8. struct Tensor3f{float xx, xy, xz, yy, yz, zz;};
  9. struct Matrix3x3f{float data[9];};
  10. struct Space2
  11. {
  12. typedef Vector2f Vector;
  13. };
  14. struct Space3
  15. {
  16. typedef Vector3f Vector;
  17. };
  18.  
  19.  
  20. template<typename T>
  21. struct ParticleData{};
  22.  
  23. template<>
  24. struct ParticleData<Space3>
  25. {
  26. Matrix3x3f orientation;
  27. Tensor3f inertiaTensor;
  28. };
  29. template<>
  30. struct ParticleData<Space2>
  31. {
  32. float orientation;
  33. float invInertia;
  34. };
  35.  
  36. template<typename Space>
  37. struct ParticleSystem
  38. {
  39. struct Particle : public ParticleData<Space>
  40. {
  41. typename Space::Vector pos, velocity;
  42. };
  43.  
  44. void DumpParticle();
  45.  
  46. void DumpParticles()
  47. {
  48. DumpParticle();
  49. }
  50.  
  51. std::vector<Particle> particles;
  52. };
  53.  
  54. template<>
  55. void ParticleSystem<Space2>::DumpParticle()
  56. {
  57. printf("%f %f", particles[0].orientation, particles[0].invInertia);
  58. }
  59.  
  60. template<>
  61. void ParticleSystem<Space3>::DumpParticle()
  62. {
  63. printf("%f %f", particles[0].orientation.data[0], particles[0].inertiaTensor.xx);
  64. }
  65.  
  66.  
  67. }
  68.  
  69. int main()
  70. {
  71. Test::ParticleSystem<Test::Space2> sys;
  72. sys.DumpParticles();
  73.  
  74. return 0;
  75. }
Runtime error #stdin #stdout 0s 2680KB
stdin
Standard input is empty
stdout
Standard output is empty