fork(1) download
  1. #include <iostream>
  2.  
  3. template <typename T, unsigned int D> struct Vec
  4. {
  5. static_assert(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. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:5:2: error: static assertion failed: Invalid dimension for vector!
  static_assert(0, "Invalid dimension for vector!");
  ^
stdout
Standard output is empty