DPC++ Runtime
Runtime libraries for oneAPI DPC++
type_list.hpp
Go to the documentation of this file.
1 //==----------- type_list.hpp - SYCL list of types utils -------------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
11 #include <sycl/access/access.hpp>
13 
14 namespace sycl {
16 namespace detail {
17 
18 template <typename T> using head_t = typename T::head;
19 
20 template <typename T> using tail_t = typename T::tail;
21 
22 // type_list
23 template <typename... T> struct type_list;
24 
26 
27 template <typename T>
29  : conditional_t<std::is_same<T, empty_type_list>::value, std::true_type,
30  std::false_type> {};
31 
32 template <> struct type_list<> {};
33 
34 template <typename Head, typename... Tail> struct type_list<Head, Tail...> {
35  using head = Head;
36  using tail = type_list<Tail...>;
37 };
38 
39 template <typename Head, typename... Tail, typename... Tail2>
40 struct type_list<type_list<Head, Tail...>, Tail2...> {
41 private:
42  using remainder = tail_t<type_list<Head>>;
43  static constexpr bool has_remainder = !is_empty_type_list<remainder>::value;
44  using without_remainder = type_list<Tail..., Tail2...>;
45  using with_remainder = type_list<remainder, Tail..., Tail2...>;
46 
47 public:
50 };
51 
52 // is_contained
53 template <typename T, typename TypeList>
55  : conditional_t<std::is_same<remove_cv_t<T>, head_t<TypeList>>::value,
56  std::true_type, is_contained<T, tail_t<TypeList>>> {};
57 
58 template <typename T>
59 struct is_contained<T, empty_type_list> : std::false_type {};
60 
61 // value_list
62 template <typename T, T... Values> struct value_list;
63 
64 template <typename T, T Head, T... Tail> struct value_list<T, Head, Tail...> {
65  static constexpr T head = Head;
66  using tail = value_list<T, Tail...>;
67 };
68 
69 template <typename T> struct value_list<T> {};
70 
71 // is_contained_value
72 template <typename T, T Value, typename ValueList>
74  : conditional_t<Value == ValueList::head, std::true_type,
75  is_contained_value<T, Value, tail_t<ValueList>>> {};
76 
77 template <typename T, T Value>
78 struct is_contained_value<T, Value, value_list<T>> : std::false_type {};
79 
80 // address_space_list
81 template <access::address_space... Values>
83 
84 template <access::address_space AddressSpace, typename ValueList>
85 using is_one_of_spaces =
87 
88 // size type predicates
89 template <typename T1, typename T2>
90 struct is_type_size_equal : bool_constant<(sizeof(T1) == sizeof(T2))> {};
91 
92 template <typename T1, typename T2>
93 struct is_type_size_greater : bool_constant<(sizeof(T1) > sizeof(T2))> {};
94 
95 template <typename T1, typename T2>
97  : bool_constant<(sizeof(T1) == (sizeof(T2) * 2))> {};
98 
99 template <typename T1, typename T2>
100 struct is_type_size_less : bool_constant<(sizeof(T1) < sizeof(T2))> {};
101 
102 template <typename T1, typename T2>
103 struct is_type_size_half_of : bool_constant<(sizeof(T1) == (sizeof(T2) / 2))> {
104 };
105 
106 // find required type
107 template <typename TypeList, template <typename, typename> class Comp,
108  typename T>
109 struct find_type {
110  using head = head_t<TypeList>;
111  using tail = typename find_type<tail_t<TypeList>, Comp, T>::type;
112  using type = conditional_t<Comp<head, T>::value, head, tail>;
113 };
114 
115 template <template <typename, typename> class Comp, typename T>
116 struct find_type<empty_type_list, Comp, T> {
117  using type = void;
118 };
119 
120 template <typename TypeList, template <typename, typename> class Comp,
121  typename T>
122 using find_type_t = typename find_type<TypeList, Comp, T>::type;
123 
124 template <typename TypeList, typename T>
125 using find_same_size_type_t = find_type_t<TypeList, is_type_size_equal, T>;
126 
127 template <typename TypeList, typename T>
128 using find_smaller_type_t = find_type_t<TypeList, is_type_size_less, T>;
129 
130 template <typename TypeList, typename T>
131 using find_larger_type_t = find_type_t<TypeList, is_type_size_greater, T>;
132 
133 template <typename TypeList, typename T>
134 using find_twice_as_small_type_t =
135  find_type_t<TypeList, is_type_size_half_of, T>;
136 
137 template <typename TypeList, typename T>
138 using find_twice_as_large_type_t =
139  find_type_t<TypeList, is_type_size_double_of, T>;
140 
141 } // namespace detail
142 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
143 } // namespace sycl
sycl::_V1::detail::is_empty_type_list
Definition: type_list.hpp:28
sycl::_V1::detail::is_type_size_less
Definition: type_list.hpp:100
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
sycl::_V1::detail::type_list< type_list< Head, Tail... >, Tail2... >::head
head_t< type_list< Head > > head
Definition: type_list.hpp:48
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
bool_constant
access.hpp
stl_type_traits.hpp
sycl::_V1::detail::is_type_size_double_of
Definition: type_list.hpp:96
sycl::_V1::detail::tail_t
typename T::tail tail_t
Definition: type_list.hpp:20
sycl::_V1::detail::type_list< type_list< Head, Tail... >, Tail2... >::tail
conditional_t< has_remainder, with_remainder, without_remainder > tail
Definition: type_list.hpp:49
sycl::_V1::detail::type_list<>
Definition: type_list.hpp:32
sycl::_V1::detail::is_type_size_equal
Definition: type_list.hpp:90
sycl::_V1::detail::is_type_size_greater
Definition: type_list.hpp:93
sycl::_V1::detail::head_t
typename T::head head_t
Definition: type_list.hpp:18
sycl::_V1::detail::is_contained_value
Definition: type_list.hpp:73
sycl::_V1::detail::type_list
Definition: type_list.hpp:23
sycl::_V1::detail::value_list
Definition: type_list.hpp:62
sycl::_V1::detail::is_contained
Definition: type_list.hpp:54
sycl::_V1::detail::type_list< Head, Tail... >::head
Head head
Definition: type_list.hpp:35
sycl::_V1::detail::conditional_t
typename std::conditional< B, T, F >::type conditional_t
Definition: stl_type_traits.hpp:27
sycl::_V1::access::address_space
address_space
Definition: access.hpp:47