-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetaFactorial.h
More file actions
54 lines (45 loc) · 928 Bytes
/
MetaFactorial.h
File metadata and controls
54 lines (45 loc) · 928 Bytes
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef _META_FACTORIAL_H_
#define _META_FACTORIAL_H_
template<size_t N>
struct MetaFactorial
{
enum { value = N * MetaFactorial<N - 1>::value };
};
template<>
struct MetaFactorial<0>
{
enum { value = 1 };
};
template <size_t N>
struct MetaDoubleFactorial
{
enum { value = N * MetaDoubleFactorial<N - 2>::value };
};
template <>
struct MetaDoubleFactorial<0>
{
enum { value = 1 };
};
template <>
struct MetaDoubleFactorial<1>
{
enum { value = 1 };
};
template<size_t N, size_t K>
struct MetaArrangements
{
static_assert(N >= K, "N can't be smaller than K");
enum { value = MetaFactorial<N>::value / MetaFactorial<N - K>::value };
};
template<size_t N, size_t K>
struct MetaCombinations
{
static_assert(N >= K, "N can't be smaller than K");
enum { value = N * MetaCombinations<N - 1, K - 1>::value / K };
};
template<size_t N>
struct MetaCombinations<N, 0>
{
enum { value = 1 };
};
#endif // _META_FACTORIAL_H_