fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. using namespace std;
  5.  
  6. template <unsigned int x>
  7. constexpr enable_if_t<x != 0U, int> log2 = x < 4U ? 1 : 1 + log2<x / 2U>;
  8.  
  9. int main() {
  10. int foo[log2<8U>];
  11.  
  12. cout << log2<8U> << endl;
  13. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/c++/6/bits/move.h:57:0,
                 from /usr/include/c++/6/bits/nested_exception.h:40,
                 from /usr/include/c++/6/exception:173,
                 from /usr/include/c++/6/ios:39,
                 from /usr/include/c++/6/ostream:38,
                 from /usr/include/c++/6/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/6/type_traits: In substitution of ‘template<bool _Cond, class _Tp> using enable_if_t = typename std::enable_if::type [with bool _Cond = (0u != 0u); _Tp = int]’:
prog.cpp:7:61:   recursively required from ‘constexpr std::enable_if_t<true, int> log2<4u>’
prog.cpp:7:61:   required from ‘constexpr std::enable_if_t<true, int> log2<8u>’
prog.cpp:10:11:   required from here
/usr/include/c++/6/type_traits:2523:61: error: no type named ‘type’ in ‘struct std::enable_if<false, int>’
     using enable_if_t = typename enable_if<_Cond, _Tp>::type;
                                                             ^
prog.cpp: In function ‘int main()’:
prog.cpp:10:19: error: size of array ‘foo’ is not an integral constant-expression
   int foo[log2<8U>];
                   ^
stdout
Standard output is empty