1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| template<int number>
struct isPrime_c
{
private:
template<int number1>
struct isEven_c
{
static const bool value = number1 % 2 == 0;
};
template<int number1, int divisor>
struct isPrime_cimpl
{
static const bool value = number1 % divisor == 0 ? false
: isPrime_cimpl<number1, divisor + 1>::value;
};
template<int number1>
struct isPrime_cimpl<number1, number1>
{
static const bool value = true;
};
public:
static_assert(number > 2, "numbers less than 3 cannot be primes");
static const bool value = isEven_c<number>::value ? false
: isPrime_cimpl<number,2>::value;
};
|