FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
meta_math.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
9
10namespace FEAT
11{
18 namespace MetaMath
19 {
29 template<int n_, int m_ = 0>
30 struct Factorial
31 {
32 // Ensure that the parameter m_ is non-negative. The case n_ = 0 is handled by specialization below.
33 static_assert(m_ >= 0, "parameter m_ must be non-negative");
34 // Ensure that n_ >= m_. The case m_ = n_ is handled by partial specialization below.
35 static_assert(n_ > m_, "parameter m_ must not be greater than parameter n_");
36
38 static constexpr int value = n_ * Factorial<n_ - 1, m_>::value;
39 }; // struct Factorial<n_,m_>
40
42 // partial specialization for n_ = m_
43 template<int n_>
44 struct Factorial<n_, n_>
45 {
46 static_assert(n_ >= 0, "parameters n_ = m_ must be non-negative");
47 static constexpr int value = n_;
48 }; // struct Factorial<n_,n_>
49
50 // explicit specialization for n_ = m_ = 0; the partial specialization above for n_ = m_ would return 0
51 template<>
52 struct Factorial<0, 0>
53 {
54 static constexpr int value = 1;
55 }; // struct Factorial<0,0>
57
67 template<int n_, int k_>
68 struct Binomial
69 {
70 // note: the valid cases k_ = 0 and k_ = n_ are specialized below
71 static_assert(k_ > 0, "parameter k_ must be non-negative");
72 static_assert(n_ > k_, "parameter k_ must not be greater than parameter n_");
73
74 // (n,k) = (n-1,k-1) + (n-1, k)
75 static constexpr int value = Binomial<n_-1,k_-1>::value + Binomial<n_-1,k_>::value;
76 }; // struct Binomial<n_,k_>
77
79 // partial specialization for k_ = n_
80 template<int n_>
81 struct Binomial<n_,n_>
82 {
83 static_assert(n_ > 0, "parameter n_ must be non-negative");
84 static constexpr int value = 1;
85 };
86
87 // partial specialization for k_ = 0
88 template<int n_>
89 struct Binomial<n_, 0>
90 {
91 static_assert(n_ > 0, "parameter n_ must be non-negative");
92 static constexpr int value = 1;
93 };
94
95 // explicit specialization for k_ = n_ = 0; this is only needed for disambiguation
96 template<>
97 struct Binomial<0, 0>
98 {
99 static constexpr int value = 1;
100 };
102 } // namespace MetaMath
103} // namespace FEAT
FEAT namespace.
Definition: adjactor.hpp:12
Binomial template meta-program.
Definition: meta_math.hpp:69
Factorial template meta-program.
Definition: meta_math.hpp:31
static constexpr int value
value of the factorial
Definition: meta_math.hpp:38