CoDiPack  3.0.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
compileTimeLoop.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2025 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://scicomp.rptu.de
6 * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de)
7 *
8 * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of CoDiPack (http://scicomp.rptu.de/software/codi).
11 *
12 * CoDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * CoDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty
19 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU General Public License for more details.
22 * You should have received a copy of the GNU
23 * General Public License along with CoDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * For other licensing options please contact us.
27 *
28 * Authors:
29 * - SciComp, University of Kaiserslautern-Landau:
30 * - Max Sagebaum
31 * - Johannes Blühdorn
32 * - Former members:
33 * - Tim Albring
34 */
35#pragma once
36
37#include <utility>
38
39#include "../config.h"
40
42namespace codi {
43
76 template<size_t T_pos, size_t T_end, int T_step>
78 public:
79
80 static size_t constexpr pos = T_pos;
81 static size_t constexpr end = T_end;
82 static int constexpr step = T_step;
83
85 template<typename Func, typename... Args>
86 static CODI_INLINE void eval(Func&& func, Args&&... args) {
87 func(std::integral_constant<size_t, pos>{}, std::forward<Args>(args)...);
88 CompileTimeLoop<pos + step, end, step>::eval(std::forward<Func>(func), std::forward<Args>(args)...);
89 }
90 };
91
93 template<size_t T_pos, int T_step>
94 struct CompileTimeLoop<T_pos, T_pos, T_step> {
95 public:
96
97 static size_t constexpr pos = T_pos;
98 static size_t constexpr end = T_pos;
99 static int constexpr step = T_step;
100
102 template<typename... Args>
103 static CODI_INLINE void eval(Args&&... args) {
104 CODI_UNUSED(args...);
105 }
106 };
107
109 template<std::size_t N, typename F, typename... Args>
110 CODI_INLINE void static_for(F func, Args&&... args) {
111 CompileTimeLoop<0, N, 1>::eval(func, std::forward<Args>(args)...);
112 }
113}
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:469
CoDiPack - Code Differentiation Package.
Definition codi.hpp:94
inlinevoid static_for(F func, Args &&... args)
Static for with i = 0 .. (N - 1). See CompileTimeLoop for details.
Definition compileTimeLoop.hpp:110
inlinevoid CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:54
static size_t constexpr end
See CompileTimeLoop.
Definition compileTimeLoop.hpp:98
static inlinevoid eval(Args &&... args)
Nothing is evaluated.
Definition compileTimeLoop.hpp:103
static size_t constexpr pos
See CompileTimeLoop.
Definition compileTimeLoop.hpp:97
static int constexpr step
See CompileTimeLoop.
Definition compileTimeLoop.hpp:99
Compile time loop evaluation.
Definition compileTimeLoop.hpp:77
static int constexpr step
See CompileTimeLoop.
Definition compileTimeLoop.hpp:82
static size_t constexpr pos
See CompileTimeLoop.
Definition compileTimeLoop.hpp:80
static size_t constexpr end
See CompileTimeLoop.
Definition compileTimeLoop.hpp:81
static inlinevoid eval(Func &&func, Args &&... args)
Func is evaluated with args as func(pos, args...)
Definition compileTimeLoop.hpp:86