PhysicsBasedAnimationToolkit 0.0.10
Cross-platform C++20 library of algorithms and data structures commonly used in computer graphics research on physically-based simulation.
Loading...
Searching...
No Matches
ConstexprFor.h
Go to the documentation of this file.
1
10
11#ifndef PBAT_COMMON_CONSTEXPRFOR_H
12#define PBAT_COMMON_CONSTEXPRFOR_H
13
14#include <type_traits>
15#include <utility>
16
17namespace pbat {
18namespace common {
19
27template <class... Ts, class F>
28constexpr void ForTypes(F&& f)
29{
30 (f.template operator()<Ts>(), ...);
31}
32
40template <auto... Xs, class F>
41constexpr void ForValues(F&& f)
42{
43 (f.template operator()<Xs>(), ...);
44}
45
54template <auto Begin, auto End, typename F>
55constexpr void ForRange(F&& f)
56{
57 using CounterType = std::common_type_t<decltype(Begin), decltype(End)>;
58
59 [&f]<auto... Is>(std::integer_sequence<CounterType, Is...>) {
60 ForValues<(Begin + Is)...>(f);
61 }(std::make_integer_sequence<CounterType, End - Begin>{});
62}
63
64} // namespace common
65} // namespace pbat
66
67#endif // PBAT_COMMON_CONSTEXPRFOR_H
Common functionality.
Definition ArgSort.h:20
constexpr void ForTypes(F &&f)
Compile-time for loop over types.
Definition ConstexprFor.h:28
constexpr void ForValues(F &&f)
Compile-time for loop over values.
Definition ConstexprFor.h:41
constexpr void ForRange(F &&f)
Compile-time for loop over a range of values.
Definition ConstexprFor.h:55
The main namespace of the library.
Definition Aliases.h:15