10
10
#include " Utilities/ErrorHandling/Assert.hpp"
11
11
#include " Utilities/Gsl.hpp"
12
12
#include " Utilities/Requires.hpp"
13
+ #include " Utilities/TMPL.hpp"
13
14
#include " Utilities/TypeTraits/IsInteger.hpp"
14
15
15
16
// / \ingroup UtilitiesGroup
@@ -35,6 +36,7 @@ struct CacheEnumeration {
35
36
constexpr static size_t size = sizeof ...(Enums);
36
37
using value_type = EnumerationType;
37
38
static constexpr std::array<value_type, size> values{Enums...};
39
+ using value_list = tmpl::integral_list<EnumerationType, Enums...>;
38
40
};
39
41
40
42
// / \ingroup UtilitiesGroup
@@ -102,7 +104,7 @@ class StaticCache {
102
104
if (UNLIKELY (array_location == std::numeric_limits<size_t >::max ())) {
103
105
ERROR (" Uncached enumeration value: " << parameter);
104
106
}
105
- return std::tuple< size_t , Range> {array_location, Range{}};
107
+ return std::tuple{array_location, typename Range::value_list {}};
106
108
} else {
107
109
static_assert (
108
110
tt::is_integer_v<std::remove_cv_t <T1>>,
@@ -120,12 +122,14 @@ class StaticCache {
120
122
<< Range::start +
121
123
static_cast <decltype (Range::start)>(Range::size));
122
124
}
123
-
124
- return std::make_tuple (
125
- static_cast <typename Range::value_type>(parameter),
126
- std::integral_constant<typename Range::value_type, Range::start>{},
127
- std::make_integer_sequence<typename Range::value_type,
128
- Range::size>{});
125
+ return std::tuple{
126
+ // unsigned cast is safe since this is an index into an array
127
+ static_cast <size_t >(
128
+ static_cast <typename Range::value_type>(parameter) -
129
+ Range::start),
130
+ tmpl::make_sequence<
131
+ tmpl::integral_constant<typename Range::value_type, Range::start>,
132
+ Range::size>{}};
129
133
}
130
134
}
131
135
@@ -135,52 +139,18 @@ class StaticCache {
135
139
return cached_object;
136
140
}
137
141
138
- template <typename ... IntegralConstantValues, auto IndexOffset, auto ... Is ,
142
+ template <typename ... IntegralConstantValues, typename ... IntegralConstants ,
139
143
typename ... Args>
140
144
const T& unwrap_cache (
141
- std::tuple<
142
- std::remove_cv_t <decltype (IndexOffset)>,
143
- std::integral_constant<std::remove_cv_t<decltype(IndexOffset)>,
144
- IndexOffset>,
145
- std::integer_sequence<std::remove_cv_t<decltype(IndexOffset)>, Is...>>
146
- parameter0,
147
- Args... parameters) const {
148
- // note that the act of assigning to the specified function pointer type
149
- // fixes the template arguments that need to be inferred.
150
- static const std::array<
151
- const T& (StaticCache<Generator, T, Ranges...>::*)(Args...) const ,
152
- sizeof ...(Is)>
153
- cache{{&StaticCache<Generator, T, Ranges...>::unwrap_cache<
154
- IntegralConstantValues...,
155
- std::integral_constant<decltype (IndexOffset),
156
- Is + IndexOffset>>...}};
157
- // The array `cache` holds pointers to member functions, so we dereference
158
- // the pointer and invoke it on `this`.
159
- #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ > 10 && __GNUC__ < 14
160
- #pragma GCC diagnostic push
161
- #pragma GCC diagnostic ignored "-Warray-bounds"
162
- #endif
163
- return (this ->*gsl::at (cache, std::get<0 >(parameter0) - IndexOffset))(
164
- parameters...);
165
- #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ > 10 && __GNUC__ < 14
166
- #pragma GCC diagnostic pop
167
- #endif
168
- }
169
-
170
- template <typename ... IntegralConstantValues, typename EnumType,
171
- EnumType... EnumValues, typename ... Args>
172
- const T& unwrap_cache (
173
- std::tuple<size_t , CacheEnumeration<EnumType, EnumValues...>>
174
- parameter0,
145
+ std::tuple<size_t , tmpl::list<IntegralConstants...>> parameter0,
175
146
Args... parameters) const {
176
147
// note that the act of assigning to the specified function pointer type
177
148
// fixes the template arguments that need to be inferred.
178
149
static const std::array<
179
150
const T& (StaticCache<Generator, T, Ranges...>::*)(Args...) const ,
180
- sizeof ...(EnumValues )>
151
+ sizeof ...(IntegralConstants )>
181
152
cache{{&StaticCache<Generator, T, Ranges...>::unwrap_cache<
182
- IntegralConstantValues...,
183
- std::integral_constant<EnumType, EnumValues>>...}};
153
+ IntegralConstantValues..., IntegralConstants>...}};
184
154
// The array `cache` holds pointers to member functions, so we dereference
185
155
// the pointer and invoke it on `this`.
186
156
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ > 10 && __GNUC__ < 14
0 commit comments