Skip to content

Commit

Permalink
Refactored detial::VariantHelper template.
Browse files Browse the repository at this point in the history
  • Loading branch information
odlomax committed Sep 16, 2024
1 parent b608818 commit ed15c84
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/atlas/array/ArrayViewVariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ struct Types {};
template <int... Is>
struct Ints {};

template <typename...>
template <typename Values, typename Ranks, typename... ArrayViews>
struct VariantHelper;

// Recursively construct ArrayView std::variant from types Ts and ranks Is.
template <typename... ArrayViews, typename T, typename... Ts, int... Is>
struct VariantHelper<Types<ArrayViews...>, Types<T, Ts...>, Ints<Is...>> {
using type = typename VariantHelper<
Types<ArrayViews..., ArrayView<const T, Is>..., ArrayView<T, Is>...>,
Types<Ts...>, Ints<Is...>>::type;
template <typename T, typename... Ts, int... Is, typename... ArrayViews>
struct VariantHelper<Types<T, Ts...>, Ints<Is...>, ArrayViews...> {
using type = typename VariantHelper<Types<Ts...>, Ints<Is...>, ArrayViews...,
ArrayView<const T, Is>...,
ArrayView<T, Is>...>::type;
};

// End recursion.
template <typename... ArrayViews, int... Is>
struct VariantHelper<Types<ArrayViews...>, Types<>, Ints<Is...>> {
template <int... Is, typename... ArrayViews>
struct VariantHelper<Types<>, Ints<Is...>, ArrayViews...> {
using type = std::variant<ArrayViews...>;
};

template <typename Values, typename Ranks>
using Variant = typename VariantHelper<Types<>, Values, Ranks>::type;
using Variant = typename VariantHelper<Values, Ranks>::type;

} // namespace detail

Expand Down

0 comments on commit ed15c84

Please sign in to comment.