From 4315eb7c73cc0f2f5660e78509e1cf8d6967034c Mon Sep 17 00:00:00 2001 From: Maarten Arnst Date: Mon, 28 Oct 2024 18:20:19 +0100 Subject: [PATCH] Add type_list_index_v --- include/kokkos-utils/impl/type_list.hpp | 17 +++++++++++++++++ tests/impl/test_type_list.cpp | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/kokkos-utils/impl/type_list.hpp b/include/kokkos-utils/impl/type_list.hpp index 1c27ea6..37eeedf 100644 --- a/include/kokkos-utils/impl/type_list.hpp +++ b/include/kokkos-utils/impl/type_list.hpp @@ -85,6 +85,23 @@ template using type_list_to_tuple_t = typename TypeListToTuple::type; ///@} +//! @name Get the index of a type in a @c Kokkos::Impl::type_list. +///@{ +template +struct TypeListIndex; + +template +struct TypeListIndex> + : std::integral_constant {}; + +template +struct TypeListIndex> + : std::integral_constant>::value> {}; + +template +inline constexpr size_t type_list_index_v = TypeListIndex::value; +///@} + } // namespace Kokkos::utils::impl #endif // KOKKOS_UTILS_IMPL_TYPE_LIST_HPP diff --git a/tests/impl/test_type_list.cpp b/tests/impl/test_type_list.cpp index f4290e0..5636b92 100644 --- a/tests/impl/test_type_list.cpp +++ b/tests/impl/test_type_list.cpp @@ -76,4 +76,14 @@ TEST(impl, type_list_to_tuple) static_assert(std::same_as, expt_tuple_t>); } +//! @test Check @ref Kokkos::utils::impl::type_list_index_v. +TEST(impl, type_list_index_v) +{ + using Kokkos::utils::impl::type_list_index_v; + + static_assert(type_list_index_v == 0); + static_assert(type_list_index_v == 1); + static_assert(type_list_index_v == 2); +} + } // namespace Kokkos::utils::tests::impl