fork download
  1. template <int n, int i, int b> struct IsPrimeIter;
  2.  
  3. template <int n, int i>
  4. struct IsPrimeIter<n, i, 0> {
  5. enum _ { Value = 0 };
  6. };
  7.  
  8. template <int n, int i>
  9. struct IsPrimeIter<n, i, 1> {
  10. enum _ { Value = 1 };
  11. };
  12.  
  13. template <int n, int i>
  14. struct IsPrimeIter<n, i, 2> {
  15. enum _ { Value = IsPrimeIter<n, i+2,
  16. (i * i > n) ? 1 :
  17. n % i == 0 ? 0 : 2>::Value };
  18. };
  19.  
  20. template <int n>
  21. struct IsPrime {
  22. enum _ { Value = n <= 1 ? false:
  23. (n == 2 || n == 3) ? true:
  24. (n % 2 == 0) ? false :
  25. IsPrimeIter<n, 3, 2>::Value };
  26. };
  27. #include <iostream>
  28. int main() {
  29. std::cout << IsPrime<1000000007>::Value;
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'struct IsPrimeIter<1000000007, 1799, 2>':
prog.cpp:15:10:   recursively required from 'struct IsPrimeIter<1000000007, 5, 2>'
prog.cpp:15:10:   required from 'struct IsPrimeIter<1000000007, 3, 2>'
prog.cpp:24:35:   required from 'struct IsPrime<1000000007>'
prog.cpp:29:34:   required from here
prog.cpp:15:10: fatal error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum)
     enum _ { Value = IsPrimeIter<n, i+2, 
          ^
compilation terminated.
stdout
Standard output is empty