fork(2) download
  1. #include <stdio.h>
  2. #include <vector>
  3. using namespace std;
  4. struct Space2
  5. {
  6. struct Vector
  7. {
  8.  
  9. };
  10.  
  11. };
  12. struct Space3
  13. {
  14. struct Vector
  15. {
  16.  
  17. };
  18.  
  19. };
  20.  
  21. template<typename Space>
  22. struct ParticleData{};
  23.  
  24. template <>
  25. struct ParticleData<Space2>
  26. {
  27. float orientation;
  28. float invInertia;
  29. ParticleData()
  30. {
  31. orientation = 2.0f ;
  32. invInertia = 3.0f;
  33. }
  34. };
  35.  
  36. template <>
  37. struct ParticleData<Space3>
  38. {
  39. float test;
  40. ParticleData()
  41. {
  42. test = 100500.0f;
  43. }
  44. };
  45.  
  46. template<typename Space,typename AwesomeParam>
  47. struct ParticleSystem
  48. {
  49. struct Particle : public ParticleData<Space>
  50. {
  51. float someGenericStuff;
  52. };
  53.  
  54. typedef ParticleSystem<Space,AwesomeParam> SelfType;
  55. typedef ParticleSystem<Space2,AwesomeParam> ParticleSystem2;
  56. typedef ParticleSystem<Space3,AwesomeParam> ParticleSystem3;
  57.  
  58.  
  59. void DumpParticle(size_t particleIndex,ParticleSystem2* dummy)
  60. {
  61. printf("2: %f %f\n", particles[particleIndex].orientation, particles[particleIndex].invInertia );
  62. }
  63.  
  64. void DumpParticle(size_t particleIndex,ParticleSystem3* dummy )
  65. {
  66. printf("3: %f\n", particles[particleIndex].test);
  67. }
  68.  
  69. void DumpParticles()
  70. {
  71. for(size_t particleIndex = 0; particleIndex < particles.size(); particleIndex++)
  72. {
  73. DumpParticle(particleIndex,this);
  74. }
  75. }
  76. ParticleSystem()
  77. {
  78. particles.push_back(Particle());
  79. }
  80. std::vector<Particle> particles;
  81. };
  82.  
  83.  
  84.  
  85. int main()
  86. {
  87. ParticleSystem<Space3,float> p3;
  88. ParticleSystem<Space2,char> p2;
  89. p3.DumpParticles();
  90. p2.DumpParticles();
  91. return 0;
  92. }
  93.  
Success #stdin #stdout 0s 2816KB
stdin
Standard input is empty
stdout
3: 100500.000000
2: 2.000000 3.000000