fork download
  1. #define furrovineexport
  2.  
  3. template<class T>
  4. class TVector2;
  5. template<class T>
  6. class TVector3;
  7.  
  8. template <class T> struct TVector4 {
  9. public:
  10. static const TVector4<T> UnitX;
  11. static const TVector4<T> UnitY;
  12. static const TVector4<T> UnitZ;
  13. static const TVector4<T> UnitW;
  14. static const TVector4<T> One;
  15. static const TVector4<T> Zero;
  16.  
  17. typedef T TElement;
  18.  
  19.  
  20. template<unsigned one, unsigned two>
  21. struct furrovineexport swizzler_two {
  22. T v[4];
  23. swizzler_two & operator= (const TVector2<T>& right) {
  24. v[one] = right.x;
  25. v[two] = right.y;
  26. return *this;
  27. }
  28. operator TVector3<T> () const { return TVector4<T>(v[one], v[two]); }
  29. };
  30. template<unsigned one, unsigned two, unsigned three>
  31. struct furrovineexport swizzler_three {
  32. T v[4];
  33. swizzler_three& operator= (const TVector3<T>& right) {
  34. v[one] = right.x;
  35. v[two] = right.y;
  36. v[three] = right.z;
  37. return *this;
  38. }
  39. operator TVector3<T> () const { return TVector4<T>(v[one], v[two], v[three]); }
  40. };
  41. template<unsigned one, unsigned two, unsigned three, unsigned four>
  42. struct furrovineexport swizzler_four {
  43. T v[4];
  44. operator TVector4<T> () const { return TVector4<T>(v[one], v[two], v[three], v[four]); }
  45. };
  46.  
  47. union {
  48. struct {T x, y, z, w;};
  49. struct {T cell[4];};
  50. swizzler_two<0, 0> xx;
  51. swizzler_two<0, 1> xy;
  52. swizzler_two<0, 2> xz;
  53. swizzler_two<0, 3> xw;
  54. swizzler_two<1, 0> yx;
  55. //etc
  56. };
  57. };
  58.  
  59. int main() {
  60. TVector4<float> a;
  61. }
  62.  
Success #stdin #stdout 0.01s 2676KB
stdin
Standard input is empty
stdout
Standard output is empty