/* * (C) Crown Copyright 2024 Met Office * * This software is licensed under the terms of the Apache Licence Version 2.0 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. */ #pragma once #include #include #include "atlas/array/ArrayView.h" namespace atlas { namespace array { namespace detail { // Container struct for a list of types. template struct Types { using add_const = Types...>; }; // Container struct for a list of integers. template struct Ints {}; template struct VariantHelper; // Recursively construct ArrayView std::variant from types Ts and ranks Is. template struct VariantHelper, Ints, ArrayViews...> { using type = typename VariantHelper, Ints, ArrayViews..., ArrayView...>::type; }; // End recursion. template struct VariantHelper, Ints, ArrayViews...> { using type = std::variant; }; template using Variant = typename VariantHelper::type; using VariantValueTypes = detail::Types; using VariantRanks = detail::Ints<1, 2, 3, 4, 5, 6, 7, 8, 9>; } // namespace detail class Array; /// @brief Variant containing all supported non-const ArrayView alternatives. using ArrayViewVariant = detail::Variant; /// @brief Variant containing all supported const ArrayView alternatives. using ConstArrayViewVariant = detail::Variant; /// @brief Create an ArrayView and assign to an ArrayViewVariant. ArrayViewVariant make_view_variant(Array& array); /// @brief Create a const ArrayView and assign to an ArrayViewVariant. ConstArrayViewVariant make_view_variant(const Array& array); /// @brief Create a host ArrayView and assign to an ArrayViewVariant. ArrayViewVariant make_host_view_variant(Array& array); /// @brief Create a const host ArrayView and assign to an ArrayViewVariant. ConstArrayViewVariant make_host_view_variant(const Array& array); /// @brief Create a device ArrayView and assign to an ArrayViewVariant. ArrayViewVariant make_device_view_variant(Array& array); /// @brief Create a const device ArrayView and assign to an ArrayViewVariant. ConstArrayViewVariant make_device_view_variant(const Array& array); /// @brief Return true if View::rank() is any of Ranks... template constexpr bool is_rank(const View&) { return ((std::decay_t::rank() == Ranks) || ...); } /// @brief Return true if View::value_type is any of ValuesTypes... template constexpr bool is_value_type(const View&) { using ValueType = typename std::decay_t::value_type; return ((std::is_same_v) || ...); } /// @brief Return true if View::non_const_value_type is any of ValuesTypes... template constexpr bool is_non_const_value_type(const View&) { using ValueType = typename std::decay_t::non_const_value_type; return ((std::is_same_v) || ...); } } // namespace array } // namespace atlas