Skip to content

Commit d9ec344

Browse files
Enable zero-sized Type in TypeMultiplier (#4617)
## Summary In C++ it is not allowed to make a zero-sized array type like `int[0]` so a more verbose way using `amrex::TypeArray<int, 0>` needs to be used. Additionally, `std::declval` is now used instead of `Types{}`. ## Additional background Zero-variants in BLAST-ImpactX/impactx#1104 ## Checklist The proposed changes: - [x] fix a bug or incorrect behavior in AMReX - [ ] add new capabilities to AMReX - [ ] changes answers in the test suite to more than roundoff level - [ ] are likely to significantly affect the results of downstream AMReX users - [ ] include documentation in the code and/or rst files, if appropriate
1 parent d44e926 commit d9ec344

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Src/Base/AMReX_TypeList.H

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ constexpr auto CartesianProduct (Ls...) {
151151
return (TypeList<TypeList<>>{} * ... * Ls{});
152152
}
153153

154+
template <class T, std::size_t N>
155+
struct TypeArray {
156+
using Type = T;
157+
static constexpr std::size_t size () noexcept { return N; }
158+
};
159+
154160
namespace detail {
155161
// return TypeList<T, T, T, T, ... (N times)> by using the fast power algorithm
156162
template <class T, std::size_t N>
@@ -173,6 +179,14 @@ namespace detail {
173179
return SingleTypeMultiplier_impl<T, N>();
174180
}
175181

182+
// overload of SingleTypeMultiplier for multiple types:
183+
// convert TypeArray<T,N> to T, T, T, T, ... (N times with N >= 0)
184+
// Note that only this overload works with N = 0
185+
template <class T, std::size_t N>
186+
constexpr auto SingleTypeMultiplier (TypeArray<T, N>) {
187+
return SingleTypeMultiplier_impl<T, N>();
188+
}
189+
176190
// overload of SingleTypeMultiplier for one regular type
177191
template <class T>
178192
constexpr auto SingleTypeMultiplier (T) {
@@ -189,13 +203,14 @@ namespace detail {
189203
/**
190204
* \brief Return the first template argument with the later arguments applied to it.
191205
* Types of the form T[N] are expanded to T, T, T, T, ... (N times with N >= 1).
206+
* Types of the form TypeArray<T,N> are expanded to T, T, T, T, ... (N times with N >= 0).
192207
*
193208
* For example, TypeMultiplier<ReduceData, Real[4], int[2], Long>
194209
* is an alias to the type ReduceData<Real, Real, Real, Real, int, int, Long>.
195210
*/
196211
template <template <class...> class TParam, class... Types>
197212
using TypeMultiplier = TypeAt<0, decltype(detail::TApply<TParam>(
198-
(TypeList<>{} + ... + detail::SingleTypeMultiplier(Types{}))
213+
(TypeList<>{} + ... + detail::SingleTypeMultiplier(std::declval<Types>()))
199214
))>;
200215

201216
}

0 commit comments

Comments
 (0)