Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Src/Base/AMReX_TypeList.H
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ constexpr auto CartesianProduct (Ls...) {
return (TypeList<TypeList<>>{} * ... * Ls{});
}

template <class T, std::size_t N>
struct TypeArray {
using Type = T;
static constexpr std::size_t size () noexcept { return N; }
};

namespace detail {
// return TypeList<T, T, T, T, ... (N times)> by using the fast power algorithm
template <class T, std::size_t N>
Expand All @@ -173,6 +179,14 @@ namespace detail {
return SingleTypeMultiplier_impl<T, N>();
}

// overload of SingleTypeMultiplier for multiple types:
// convert TypeArray<T,N> to T, T, T, T, ... (N times with N >= 0)
// Note that only this overload works with N = 0
template <class T, std::size_t N>
constexpr auto SingleTypeMultiplier (TypeArray<T, N>) {
return SingleTypeMultiplier_impl<T, N>();
}

// overload of SingleTypeMultiplier for one regular type
template <class T>
constexpr auto SingleTypeMultiplier (T) {
Expand All @@ -189,13 +203,14 @@ namespace detail {
/**
* \brief Return the first template argument with the later arguments applied to it.
* Types of the form T[N] are expanded to T, T, T, T, ... (N times with N >= 1).
* Types of the form TypeArray<T,N> are expanded to T, T, T, T, ... (N times with N >= 0).
*
* For example, TypeMultiplier<ReduceData, Real[4], int[2], Long>
* is an alias to the type ReduceData<Real, Real, Real, Real, int, int, Long>.
*/
template <template <class...> class TParam, class... Types>
using TypeMultiplier = TypeAt<0, decltype(detail::TApply<TParam>(
(TypeList<>{} + ... + detail::SingleTypeMultiplier(Types{}))
(TypeList<>{} + ... + detail::SingleTypeMultiplier(std::declval<Types>()))
))>;

}
Expand Down
Loading