fork download
  1. #include <type_traits>
  2.  
  3. template <std::size_t... Ts>
  4. struct not_zero {};
  5.  
  6. template <std::size_t N>
  7. struct not_zero<N> : std::integral_constant<bool, N> {};
  8.  
  9. template <std::size_t N, std::size_t... Ts>
  10. struct not_zero<N, Ts...> : std::integral_constant<bool, N && not_zero<Ts...>::value> {};
  11.  
  12. template <typename T, std::size_t... Ts>
  13. struct Array
  14. {
  15. static_assert(not_zero<Ts...>::value, "Dimension cannot be 0");
  16. };
  17.  
  18. template struct Array<int, 3>;
  19. template struct Array<int, 3, 2, 1, 0>;
  20.  
  21. int main () {}
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘struct Array<int, 3u, 2u, 1u, 0u>’:
prog.cpp:19:17:   required from here
prog.cpp:15:5: error: static assertion failed: Dimension cannot be 0
stdout
Standard output is empty