-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add utilities that extend Kokkos::Impl::type_list
- Loading branch information
1 parent
f00438d
commit 6d40405
Showing
5 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <typename> | ||
struct TypeListSize; | ||
|
||
template <typename... Ts> | ||
struct TypeListSize<Kokkos::Impl::type_list<Ts...>> : std::integral_constant<size_t, sizeof...(Ts)> {}; | ||
|
||
template <typename T> | ||
inline constexpr size_t type_list_size_v = TypeListSize<T>::value; | ||
///@} | ||
|
||
//! @name Get the @p I th type in a @c Kokkos::Impl::type_list. | ||
///@{ | ||
template <size_t, typename> | ||
struct TypeListAt; | ||
|
||
template <size_t I, typename Head, typename... Tail> | ||
struct TypeListAt<I, Kokkos::Impl::type_list<Head, Tail...>> | ||
: TypeListAt<I - 1, Kokkos::Impl::type_list<Tail...>> {}; | ||
|
||
template <class Head, class... Tail> | ||
struct TypeListAt<0, Kokkos::Impl::type_list<Head, Tail...>> | ||
{ | ||
using type = Head; | ||
}; | ||
|
||
template <size_t I, typename T> | ||
using type_list_at_t = typename TypeListAt<I, T>::type; | ||
///@} | ||
|
||
//! @name Transform a @c Kokkos::Impl::type_list. | ||
///@{ | ||
template <template <typename> typename, typename> | ||
struct TransformTypeList; | ||
|
||
template <template <typename> typename TransformerType, typename... Ts> | ||
struct TransformTypeList<TransformerType, Kokkos::Impl::type_list<Ts...>> | ||
{ | ||
using type = Kokkos::Impl::concat_type_list_t<Kokkos::Impl::type_list<typename TransformerType<Ts>::type...>>; | ||
}; | ||
|
||
template <template <typename> typename TransformerType, typename T> | ||
using transform_type_list_t = typename TransformTypeList<TransformerType, T>::type; | ||
///@} | ||
|
||
//! @name Convert a @c Kokkos::Impl::type_list into a @c std::tuple. | ||
///@{ | ||
template <typename> | ||
struct TypeListToTuple; | ||
|
||
template <typename... Ts> | ||
struct TypeListToTuple<Kokkos::Impl::type_list<Ts...>> | ||
{ | ||
using type = std::tuple<Ts...>; | ||
}; | ||
|
||
template <typename T> | ||
using type_list_to_tuple_t = typename TypeListToTuple<T>::type; | ||
///@} | ||
|
||
} // namespace Kokkos::utils::impl | ||
|
||
#endif // KOKKOS_UTILS_IMPL_TYPE_LIST_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "gtest/gtest.h" | ||
|
||
#include "kokkos-utils/impl/type_list.hpp" | ||
|
||
/** | ||
* @file | ||
* | ||
* @addtogroup unittests | ||
* | ||
* **Type list** | ||
* | ||
* This group of tests check the behavior of our utilities extending @c Kokkos::Impl::type_list. | ||
*/ | ||
|
||
namespace Kokkos::utils::tests::impl | ||
{ | ||
|
||
using type_list_t = Kokkos::Impl::type_list<char, short, int>; | ||
|
||
//! @test Check @ref Kokkos::utils::impl::type_list_size_v. | ||
TEST(impl, type_list_size_v) | ||
{ | ||
using Kokkos::utils::impl::type_list_size_v; | ||
|
||
using type_list_empty_t = Kokkos::Impl::type_list<>; | ||
static_assert(type_list_size_v<type_list_empty_t> == 0); | ||
|
||
static_assert(type_list_size_v<type_list_t> == 3); | ||
} | ||
|
||
//! @test Check @ref Kokkos::utils::impl::type_list_at_t. | ||
TEST(impl, type_list_at_t) | ||
{ | ||
using Kokkos::utils::impl::type_list_at_t; | ||
|
||
static_assert(std::same_as<type_list_at_t<0, type_list_t>, char>); | ||
static_assert(std::same_as<type_list_at_t<1, type_list_t>, short>); | ||
static_assert(std::same_as<type_list_at_t<2, type_list_t>, int>); | ||
} | ||
|
||
//! Helper struct for the test of @ref Kokkos::utils::impl::transform_type_list_t. | ||
template <typename T> | ||
struct VectorOfTransformer | ||
{ | ||
using type = std::vector<T>; | ||
}; | ||
|
||
//! @test Check @ref Kokkos::utils::impl::transform_type_list_t. | ||
TEST(impl, transform_type_list_t) | ||
{ | ||
using Kokkos::utils::impl::transform_type_list_t; | ||
|
||
using transformed_type_list_t = transform_type_list_t<VectorOfTransformer, type_list_t>; | ||
|
||
using expt_transformed_type_list_t = Kokkos::Impl::type_list<std::vector<char>, std::vector<short>, std::vector<int>>; | ||
|
||
static_assert(std::same_as<transformed_type_list_t, expt_transformed_type_list_t>); | ||
} | ||
|
||
//! @test Check @ref Kokkos::utils::impl::type_list_to_tuple_t. | ||
TEST(impl, type_list_to_tuple) | ||
{ | ||
using Kokkos::utils::impl::type_list_to_tuple_t; | ||
|
||
using expt_tuple_t = std::tuple<char, short, int>; | ||
|
||
static_assert(std::same_as<type_list_to_tuple_t<type_list_t>, expt_tuple_t>); | ||
} | ||
|
||
} // namespace Kokkos::utils::tests::impl |