flexiblesusy is hosted by Hepforge, IPPP Durham
FlexibleSUSY
for_each.hpp
Go to the documentation of this file.
1// ====================================================================
2// This file is part of FlexibleSUSY.
3//
4// FlexibleSUSY is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published
6// by the Free Software Foundation, either version 3 of the License,
7// or (at your option) any later version.
8//
9// FlexibleSUSY is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with FlexibleSUSY. If not, see
16// <http://www.gnu.org/licenses/>.
17// ====================================================================
18
19#ifndef FOR_EACH_H
20#define FOR_EACH_H
21
22#include <tuple>
23
24namespace flexiblesusy {
25
26namespace detail
27{
28 template<int... Is>
29 struct seq {};
30
31 template<int N, int... Is>
32 struct gen_seq : gen_seq<N - 1, N - 1, Is...> {};
33
34 template<int... Is>
35 struct gen_seq<0, Is...> : seq<Is...> {};
36
37 template<typename T, typename F, int... Is>
38 void for_each(T&& t, F f, seq<Is...>)
39 {
40 [[maybe_unused]] auto l = { (f(std::get<Is>(t)), 0)... };
41 }
42} // namespace detail
43
45template<typename... Ts, typename F>
46void for_each_in_tuple(std::tuple<Ts...> const& t, F f)
47{
48 detail::for_each(t, f, detail::gen_seq<sizeof...(Ts)>());
49}
50
51} // namespace flexiblesusy
52
53#endif
void for_each(T &&t, F f, seq< Is... >)
Definition: for_each.hpp:38
std::complex< double > f(double tau) noexcept
void for_each_in_tuple(std::tuple< Ts... > const &t, F f)
applies f on each element of the tuple
Definition: for_each.hpp:46