kokkos-utils 0.0.1
 
Loading...
Searching...
No Matches
type_list.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_UTILS_IMPL_TYPE_LIST_HPP
2#define KOKKOS_UTILS_IMPL_TYPE_LIST_HPP
3
4#include "impl/Kokkos_Utilities.hpp"
5
11
13{
16template <typename T>
17struct is_type_list : public std::false_type {};
18
19template <typename... T>
20struct is_type_list<Kokkos::Impl::type_list<T...>> : public std::true_type {};
21
22template <typename T>
23inline constexpr bool is_type_list_v = is_type_list<T>::value;
25
28template <typename...>
30
31template <typename T> requires Kokkos::utils::impl::is_type_list_v<T>
33{
34 using type = T;
35};
36
37template <typename T, typename... Ts>
38struct make_type_list<T, Ts...>
39{
40 using type = Kokkos::Impl::type_list<T, Ts...>;
41};
42
43template <typename... Args>
44using make_type_list_t = typename make_type_list<Args...>::type;
46
49template <typename>
51
52template <typename... Ts>
53struct TypeListSize<Kokkos::Impl::type_list<Ts...>> : std::integral_constant<size_t, sizeof...(Ts)> {};
54
55template <typename T>
56inline constexpr size_t type_list_size_v = TypeListSize<T>::value;
58
61template <typename, typename...>
63
65template <typename U, typename T, typename... Ts>
66struct TypeListContains<U, T, Ts...> : public std::disjunction<std::is_same<U, T>, std::is_same<U, Ts>...> {};
67
69template <typename U, typename... Ts>
70struct TypeListContains<U, Kokkos::Impl::type_list<Ts...>> : std::disjunction<std::is_same<U, Ts>...> {};
71
72template <typename U, typename... TypeList>
73inline constexpr bool type_list_contains_v = TypeListContains<U, TypeList...>::value;
75
78template <size_t, typename>
80
81template <size_t I, typename Head, typename... Tail>
82struct TypeListAt<I, Kokkos::Impl::type_list<Head, Tail...>>
83 : TypeListAt<I - 1, Kokkos::Impl::type_list<Tail...>> {};
84
85template <class Head, class... Tail>
86struct TypeListAt<0, Kokkos::Impl::type_list<Head, Tail...>>
87{
88 using type = Head;
89};
90
91template <size_t I, typename T>
94
97template <template <typename> typename, typename>
99
100template <template <typename> typename TransformerType, typename... Ts>
101struct TransformTypeList<TransformerType, Kokkos::Impl::type_list<Ts...>>
102{
103 using type = Kokkos::Impl::concat_type_list_t<Kokkos::Impl::type_list<typename TransformerType<Ts>::type...>>;
104};
105
106template <template <typename> typename TransformerType, typename T>
109
112template <typename>
114
115template <typename... Ts>
116struct TypeListToTuple<Kokkos::Impl::type_list<Ts...>>
117{
118 using type = std::tuple<Ts...>;
119};
120
121template <typename T>
124
127template <typename, typename>
129
130template <typename T, typename... Ts>
131struct TypeListIndex<T, Kokkos::Impl::type_list<T, Ts...>>
132 : std::integral_constant<size_t, 0> {};
133
134template <typename T, typename Head, typename... Ts>
135struct TypeListIndex<T, Kokkos::Impl::type_list<Head, Ts...>>
136 : std::integral_constant<size_t, 1 + TypeListIndex<T, Kokkos::Impl::type_list<Ts...>>::value> {};
137
138template <typename T, typename S>
141
144template <template <typename> typename UnaryPred, typename...>
146
148template <template <typename> typename UnaryPred, typename T, typename... Ts>
149struct type_list_all<UnaryPred, T, Ts...>
150 : public std::conjunction<UnaryPred<T>, UnaryPred<Ts>...> {};
151
153template <template <typename> typename UnaryPred, typename... Ts>
154struct type_list_all<UnaryPred, Kokkos::Impl::type_list<Ts...>>
155 : public std::conjunction<UnaryPred<Ts>...> {};
156
157template <template <typename> typename UnaryPred, typename... TypeList>
158inline constexpr bool type_list_all_v = type_list_all<UnaryPred, TypeList...>::value;
160
168template <template <typename> typename UnaryPred, typename...>
170
178#if defined(__NVCC__)
179template <template <typename> typename UnaryPred, typename T, typename... Ts>
180struct type_list_any<UnaryPred, T, Ts...>
181 : public std::bool_constant<UnaryPred<T>::value || (UnaryPred<Ts>::value || ...)> {};
182#else
183template <template <typename> typename UnaryPred, typename T, typename... Ts>
184struct type_list_any<UnaryPred, T, Ts...>
185 : public std::disjunction<UnaryPred<T>, UnaryPred<Ts>...> {};
186#endif
188
196#if defined(__NVCC__)
197template <template <typename> typename UnaryPred, typename... Ts>
198struct type_list_any<UnaryPred, Kokkos::Impl::type_list<Ts...>>
199 : public std::bool_constant<(UnaryPred<Ts>::value || ...)> {};
200#else
201template <template <typename> typename UnaryPred, typename... Ts>
202struct type_list_any<UnaryPred, Kokkos::Impl::type_list<Ts...>>
203 : public std::disjunction<UnaryPred<Ts>...> {};
204#endif
206
207template <template <typename> typename UnaryPred, typename... TypeList>
208inline constexpr bool type_list_any_v = type_list_any<UnaryPred, TypeList...>::value;
210
212template <typename TypeList, typename Callable>
213constexpr void for_each(Callable callable)
214{
215 [&] <size_t... Is>(std::index_sequence<Is...>) constexpr {
216 (callable.template operator()<type_list_at_t<Is, TypeList>>(), ...);
217 }(std::make_index_sequence<type_list_size_v<TypeList>>{});
218}
219
220} // namespace Kokkos::utils::impl
221
222#endif // KOKKOS_UTILS_IMPL_TYPE_LIST_HPP
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 make_type_list< Args... >::type make_type_list_t
Definition type_list.hpp:44
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
Kokkos::Impl::concat_type_list_t< Kokkos::Impl::type_list< typename TransformerType< Ts >::type... > > type
Kokkos::Impl::type_list< T, Ts... > type
Definition type_list.hpp:40