fork(2) download
  1. #include <iostream>
  2.  
  3. template <typename T, unsigned int D> struct Vec
  4. {
  5. static_assert(D && 0, "Invalid dimension for vector!");
  6. };
  7.  
  8. template <typename T> struct Vec<T, 1> {union {T x, r;};};
  9. template <typename T> struct Vec<T, 2> : Vec<T, 1> {union {T y, g;};};
  10. template <typename T> struct Vec<T, 3> : Vec<T, 2> {union {T z, b;};};
  11. template <typename T> struct Vec<T, 4> : Vec<T, 3> {union {T w, a;};};
  12.  
  13. int main()
  14. {
  15. Vec<float, 3> v;
  16. v.x = 1;
  17. v.y = 2;
  18. v.z = 3;
  19.  
  20. return 0;
  21. }
Success #stdin #stdout 0s 3136KB
stdin
Standard input is empty
stdout
Standard output is empty