Skip to content

Commit

Permalink
Merge pull request #22 from maartenarnst/type_list_contains
Browse files Browse the repository at this point in the history
Add predicate to know whether a type is contained in a type list
  • Loading branch information
romintomasetti authored Oct 21, 2024
2 parents fb6841e + 4fdec8e commit 961c6ff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/kokkos-utils/impl/type_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ template <typename T>
inline constexpr size_t type_list_size_v = TypeListSize<T>::value;
///@}

//! @name Whether a type is contained in a @c Kokkos::Impl::type_list.
///@{
template <typename, typename>
struct TypeListContains;

template <typename T, typename... Ts>
struct TypeListContains<T, Kokkos::Impl::type_list<Ts...>> : std::disjunction<std::is_same<T, Ts>...> {};

template <typename T, typename S>
inline constexpr bool type_list_contains_v = TypeListContains<T, S>::value;
///@}

//! @name Get the @p I th type in a @c Kokkos::Impl::type_list.
///@{
template <size_t, typename>
Expand Down
9 changes: 9 additions & 0 deletions tests/impl/test_type_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ TEST(impl, type_list_size_v)
static_assert(type_list_size_v<type_list_t> == 3);
}

//! @test Check @ref Kokkos::utils::impl::type_list_contains_v.
TEST(impl, type_list_contains_v)
{
using Kokkos::utils::impl::type_list_contains_v;

static_assert( type_list_contains_v<char, type_list_t>);
static_assert( ! type_list_contains_v<double, type_list_t>);
}

//! @test Check @ref Kokkos::utils::impl::type_list_at_t.
TEST(impl, type_list_at_t)
{
Expand Down

0 comments on commit 961c6ff

Please sign in to comment.