Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.61 KB | None | 0 0
  1. struct Vector(T, int dimension) if(__traits(isArithmetic, T))
  2. {
  3.     static assert(dimension > 0, "Dimension must be positive and non-zero.");
  4.  
  5.     static if(dimension == 1)
  6.     {
  7.         public T X;
  8.         this(T x)
  9.         {
  10.             X = x;
  11.         }
  12.     }
  13.     else static if(dimension == 2)
  14.     {
  15.         public T X, Y;
  16.         this(T x, T y)
  17.         {
  18.             X = x;
  19.             Y = y;
  20.         }
  21.     }
  22.     else static if(dimension == 3)
  23.     {
  24.         public T X, Y, Z;
  25.         this(T x, T y, T z)
  26.         {
  27.             X = x;
  28.             Y = y;
  29.             Z = z;
  30.         }
  31.     }
  32.     else static if(dimension == 4)
  33.     {
  34.         public T X, Y, Z, W;
  35.         this(T x, T y, T z, T w)
  36.         {
  37.             X = x;
  38.             Y = y;
  39.             Z = z;
  40.             W = w;
  41.         }
  42.     }
  43.     // ...
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement