From 6d40405e7a8e63455281444c531b63806c933dc6 Mon Sep 17 00:00:00 2001 From: Maarten Arnst Date: Mon, 2 Sep 2024 14:10:45 +0200 Subject: [PATCH] add utilities that extend Kokkos::Impl::type_list --- CMakeLists.txt | 1 + include/kokkos-utils/impl/type_list.hpp | 78 +++++++++++++++++++++++ include/kokkos-utils/impl/type_traits.hpp | 5 +- tests/impl/CMakeLists.txt | 5 ++ tests/impl/test_type_list.cpp | 70 ++++++++++++++++++++ 5 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 include/kokkos-utils/impl/type_list.hpp create mode 100644 tests/impl/test_type_list.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 19c9c7b..8e7e455 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,7 @@ target_sources( include/kokkos-utils/concepts/Space.hpp include/kokkos-utils/concepts/View.hpp + include/kokkos-utils/impl/type_list.hpp include/kokkos-utils/impl/type_traits.hpp include/kokkos-utils/view/extents.hpp diff --git a/include/kokkos-utils/impl/type_list.hpp b/include/kokkos-utils/impl/type_list.hpp new file mode 100644 index 0000000..8ba4aef --- /dev/null +++ b/include/kokkos-utils/impl/type_list.hpp @@ -0,0 +1,78 @@ +#ifndef KOKKOS_UTILS_IMPL_TYPE_LIST_HPP +#define KOKKOS_UTILS_IMPL_TYPE_LIST_HPP + +#include "impl/Kokkos_Utilities.hpp" + +/** + * @file + * + * This file provides extensions to the @c Kokkos::Impl::type_list struct in @c Kokkos_Utilities.hpp. + */ + +namespace Kokkos::utils::impl +{ + +//! @name Get the number of types in a @c Kokkos::Impl::type_list. +///@{ +template +struct TypeListSize; + +template +struct TypeListSize> : std::integral_constant {}; + +template +inline constexpr size_t type_list_size_v = TypeListSize::value; +///@} + +//! @name Get the @p I th type in a @c Kokkos::Impl::type_list. +///@{ +template +struct TypeListAt; + +template +struct TypeListAt> + : TypeListAt> {}; + +template +struct TypeListAt<0, Kokkos::Impl::type_list> +{ + using type = Head; +}; + +template +using type_list_at_t = typename TypeListAt::type; +///@} + +//! @name Transform a @c Kokkos::Impl::type_list. +///@{ +template