BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Precomputed.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Base/Utils/Precomputed.h
6 //! @brief Defines namespace Precomputed, providing precomputed constants
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
15 #ifndef BORNAGAIN_BASE_UTILS_PRECOMPUTED_H
16 #define BORNAGAIN_BASE_UTILS_PRECOMPUTED_H
17 
18 #include <array>
19 #include <utility>
20 #include <vector>
21 
22 //! Compile-time generated std::array of reciprocal factorials
23 namespace Precomputed
24 {
25 template <size_t N> struct ReciprocalFactorial {
26  static constexpr double value = ReciprocalFactorial<N - 1>::value / N;
27 };
28 
29 template <> struct ReciprocalFactorial<0> {
30  static constexpr double value = 1.0;
31 };
32 
33 template <template <size_t> class F, size_t... I>
34 constexpr std::array<double, sizeof...(I)> GenerateArrayHelper(std::index_sequence<I...>)
35 {
36  return {F<I>::value...};
37 };
38 
39 template <size_t N, typename Indices = std::make_index_sequence<N>>
40 constexpr std::array<double, N> GenerateReciprocalFactorialArray()
41 {
42  return GenerateArrayHelper<ReciprocalFactorial>(Indices{});
43 };
44 } // namespace Precomputed
45 
46 #endif // BORNAGAIN_BASE_UTILS_PRECOMPUTED_H
constexpr complex_t I
Definition: Complex.h:21
Compile-time generated std::array of reciprocal factorials.
Definition: Precomputed.h:24
constexpr std::array< double, sizeof...(I)> GenerateArrayHelper(std::index_sequence< I... >)
Definition: Precomputed.h:34
constexpr std::array< double, N > GenerateReciprocalFactorialArray()
Definition: Precomputed.h:40
static constexpr double value
Definition: Precomputed.h:26