fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<typename T,int N> constexpr bool bounds_check(T (&array)[N], int i)
  5. {
  6. return i < N;
  7. }
  8.  
  9. int main() {
  10. int a[] = { 21, 213, 45 };
  11. static_assert(bounds_check(a, 22), "error for a\n");
  12. return 0;
  13. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:11:5: error: static assertion failed: error for a

     static_assert(bounds_check(a, 22), "error for a\n");
     ^
stdout
Standard output is empty