kokkos-utils 0.0.1
 
Loading...
Searching...
No Matches
test_type_list.cpp
Go to the documentation of this file.
1#include "gtest/gtest.h"
2
4
14
16{
17
18using type_list_t = Kokkos::Impl::type_list<char, short, int>;
19
30
32TEST(impl, make_type_list_t)
33{
34 static_assert(std::same_as<Kokkos::utils::impl::make_type_list_t<int >, Kokkos::Impl::type_list<int >>);
35 static_assert(std::same_as<Kokkos::utils::impl::make_type_list_t<int, double>, Kokkos::Impl::type_list<int, double>>);
36
37 static_assert(std::same_as<Kokkos::utils::impl::make_type_list_t<type_list_t>, type_list_t>);
38}
39
41TEST(impl, type_list_size_v)
42{
44
45 using type_list_empty_t = Kokkos::Impl::type_list<>;
46 static_assert(type_list_size_v<type_list_empty_t> == 0);
47
48 static_assert(type_list_size_v<type_list_t> == 3);
49}
50
52TEST(impl, type_list_contains_v)
53{
55
56 static_assert( type_list_contains_v<char, type_list_t>);
57 static_assert( ! type_list_contains_v<double, type_list_t>);
58
59 static_assert( type_list_contains_v<char, int, double, char>);
60 static_assert( ! type_list_contains_v<char, int, double, const char>);
61}
62
64TEST(impl, type_list_at_t)
65{
67
68 static_assert(std::same_as<type_list_at_t<0, type_list_t>, char>);
69 static_assert(std::same_as<type_list_at_t<1, type_list_t>, short>);
70 static_assert(std::same_as<type_list_at_t<2, type_list_t>, int>);
71}
72
74template <typename T>
76{
77 using type = std::vector<T>;
78};
79
81TEST(impl, transform_type_list_t)
82{
84
85 using transformed_type_list_t = transform_type_list_t<VectorOfTransformer, type_list_t>;
86
87 using expt_transformed_type_list_t = Kokkos::Impl::type_list<std::vector<char>, std::vector<short>, std::vector<int>>;
88
89 static_assert(std::same_as<transformed_type_list_t, expt_transformed_type_list_t>);
90}
91
93TEST(impl, type_list_to_tuple)
94{
96
97 using expt_tuple_t = std::tuple<char, short, int>;
98
99 static_assert(std::same_as<type_list_to_tuple_t<type_list_t>, expt_tuple_t>);
100}
101
103TEST(impl, type_list_index_v)
104{
106
107 static_assert(type_list_index_v<char, type_list_t> == 0);
108 static_assert(type_list_index_v<short, type_list_t> == 1);
109 static_assert(type_list_index_v<int, type_list_t> == 2);
110}
111
121
133
135TEST(impl, for_each)
136{
138
139 static_assert([]() {
140 size_t sum_of_sizes = 0;
141
142 for_each<type_list_t>([&] <typename T>() constexpr {
143 sum_of_sizes += sizeof(T);
144 });
145
146 return sum_of_sizes == sizeof(char) + sizeof(short) + sizeof(int);
147 }());
148}
149
150} // namespace Kokkos::utils::tests::impl
constexpr bool type_list_all_v
constexpr size_t type_list_size_v
Definition type_list.hpp:56
constexpr bool type_list_contains_v
Definition type_list.hpp:73
constexpr bool type_list_any_v
constexpr void for_each(Callable callable)
Calls the instantiation of the call operator of a callable object for each type in a Kokkos::Impl::ty...
typename TransformTypeList< TransformerType, T >::type transform_type_list_t
typename TypeListToTuple< T >::type type_list_to_tuple_t
constexpr bool is_type_list_v
Definition type_list.hpp:23
constexpr size_t type_list_index_v
typename TypeListAt< I, T >::type type_list_at_t
Definition type_list.hpp:92
TEST(impl, is_type_list_v)
Kokkos::Impl::type_list< char, short, int > type_list_t
Helper struct for the test of Kokkos::utils::impl::transform_type_list_t.