[ create a new paste ] login | about

Link: http://codepad.org/atcwkCSJ    [ raw code | output | fork ]

aaronla - C++, pasted on Aug 15:
template <int n, int m>
struct trial_divide_composite
{
  enum { value = (n%m == 0) || trial_divide_composite<n, m-1>::value };
};
template <int n>
struct trial_divide_composite<n, 1>
{
  enum { value = 0 };
};
template <int n>
struct is_prime
{
  enum { value = !trial_divide_composite<n,n/2>::value };
};

template <> struct is_prime<2> { enum { value = 1 }; };

template <bool _>
struct compile_successfully;

template <>
struct compile_successfully<true> {};

int main()
{
  compile_successfully<(bool)is_prime<  42  >::value > _;
}


Output:
1
2
3
In function 'int main()':
Line 27: error: aggregate 'compile_successfully<false> _' has incomplete type and cannot be defined
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: