VTK  9.3.20240229
vtkImplicitArrayTraits.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Funded by CEA, DAM, DIF, F-91297 Arpajon, France
4 #ifndef vtkImplicitArrayTraits_h
5 #define vtkImplicitArrayTraits_h
6 
7 #include "vtkSystemIncludes.h"
8 #include <numeric>
9 #include <type_traits>
10 
35 namespace vtk
36 {
37 namespace detail
38 {
39 
40 VTK_ABI_NAMESPACE_BEGIN
41 
42 template <typename... Ts>
43 struct make_void
44 {
45  using type = void;
46 };
47 
48 template <typename... Ts>
49 using void_t = typename make_void<Ts...>::type;
50 
52 
56 template <typename, typename = void>
57 struct has_map_trait : std::false_type
58 {
59 };
60 
61 template <typename T>
62 struct has_map_trait<T, void_t<decltype(&std::remove_reference<T>::type::map)>>
63  : public has_map_trait<decltype(&std::remove_reference<T>::type::map)>
64 {
65  using type = T;
66 };
67 
68 template <typename T>
69 struct has_map_trait<T*> : public has_map_trait<T>
70 {
71 };
72 
73 template <typename T>
74 struct has_map_trait<const T> : public has_map_trait<T>
75 {
76 };
77 
78 template <typename R, typename T, typename Arg>
79 struct has_map_trait<R (T::*)(Arg) const> : public has_map_trait<R(Arg)>
80 {
81 };
82 
83 template <typename R, typename Arg>
84 struct has_map_trait<R(Arg)>
85 {
86  static_assert(std::is_integral<Arg>::value, "Argument to map must be integral type");
87  static constexpr bool value = true;
88  using rtype = R;
89 };
91 
93 
97 template <typename, typename = void>
98 struct is_closure_trait : std::false_type
99 {
100 };
101 
102 template <typename Closure>
103 struct is_closure_trait<Closure, void_t<decltype(&Closure::operator())>>
104  : public is_closure_trait<decltype(&Closure::operator())>
105 {
106  using type = Closure;
107 };
108 
109 template <typename Closure>
111 {
112 };
113 
114 template <typename Closure>
115 struct is_closure_trait<const Closure> : public is_closure_trait<Closure>
116 {
117 };
118 
119 template <typename Closure>
121 {
122 };
123 
124 template <typename Closure, typename R, typename Arg>
125 struct is_closure_trait<R (Closure::*)(Arg) const> : public is_closure_trait<R(Arg)>
126 {
127 };
128 
129 template <typename R, typename Arg>
130 struct is_closure_trait<R (*)(Arg)> : public is_closure_trait<R(Arg)>
131 {
132 };
133 
134 template <typename R, typename Arg>
135 struct is_closure_trait<R(Arg)>
136 {
137  static_assert(std::is_integral<Arg>::value, "Argument to closure must be integral type");
138  static constexpr bool value = true;
139  using rtype = R;
140 };
142 
144 
148 template <typename, typename = void>
149 struct has_map_tuple_trait : std::false_type
150 {
151 };
152 
153 template <typename T>
154 struct has_map_tuple_trait<T, void_t<decltype(&std::remove_reference<T>::type::mapTuple)>>
155  : public has_map_tuple_trait<decltype(&std::remove_reference<T>::type::mapTuple)>
156 {
157  using type = T;
158 };
159 
160 template <typename T>
162 {
163 };
164 
165 template <typename T>
166 struct has_map_tuple_trait<const T> : public has_map_tuple_trait<T>
167 {
168 };
169 
170 template <typename T, typename ArgIdx, typename ArgTup>
171 struct has_map_tuple_trait<void (T::*)(ArgIdx, ArgTup*) const>
172  : public has_map_tuple_trait<void(ArgIdx, ArgTup*)>
173 {
174 };
175 
176 template <typename ArgIdx, typename ArgTup>
177 struct has_map_tuple_trait<void(ArgIdx, ArgTup*)>
178 {
179  static_assert(std::is_integral<ArgIdx>::value, "Argument to mapTuple must be integral type");
180  static constexpr bool value = true;
181  using rtype = ArgTup;
182 };
184 
186 
190 template <typename, typename = void>
191 struct has_map_component_trait : std::false_type
192 {
193 };
194 
195 template <typename T>
196 struct has_map_component_trait<T, void_t<decltype(&std::remove_reference<T>::type::mapComponent)>>
197  : public has_map_component_trait<decltype(&std::remove_reference<T>::type::mapComponent)>
198 {
199  using type = T;
200 };
201 
202 template <typename T>
204 {
205 };
206 
207 template <typename T>
209 {
210 };
211 
212 template <typename R, typename T, typename ArgTupIdx, typename ArgCompIdx>
213 struct has_map_component_trait<R (T::*)(ArgTupIdx, ArgCompIdx) const>
214  : public has_map_component_trait<R(ArgTupIdx, ArgCompIdx)>
215 {
216 };
217 
218 template <typename R, typename ArgTupIdx, typename ArgCompIdx>
219 struct has_map_component_trait<R(ArgTupIdx, ArgCompIdx)>
220 {
221  static_assert(
222  std::is_integral<ArgTupIdx>::value, "1st Argument to mapComponent must be integral type");
223  static_assert(
224  std::is_integral<ArgCompIdx>::value, "2nd Argument to mapComponent must be integral type");
225  static constexpr bool value = true;
226  using rtype = R;
227 };
229 
230 namespace iarrays
231 {
238 {
241  CLOSURE
242 };
243 }
244 
246 
250 template <typename T, typename = void>
252 {
253  using type = T;
254  static constexpr bool value = false;
255  using rtype = void;
257 };
258 
259 template <typename T>
260 struct can_map_trait<T, void_t<typename has_map_trait<T>::rtype>>
261 {
262  using type = T;
263  static constexpr bool value = true;
264  using rtype = typename has_map_trait<T>::rtype;
266 };
268 
270 
274 template <typename T, typename = void>
276 {
277  using type = T;
278  static constexpr bool value = false;
279  using rtype = void;
281 };
282 
283 template <typename T>
285 {
286  using type = T;
287  static constexpr bool value = true;
290 };
292 
294 
298 template <typename T, typename = void>
300 {
301  using type = T;
302  static constexpr bool value = false;
303  using rtype = void;
304 };
305 
306 template <typename T>
308 {
309  using type = T;
310  static constexpr bool value = true;
312 };
314 
316 
320 template <typename T, typename = void>
322 {
323  using type = T;
324  static constexpr bool value = false;
325  using rtype = void;
326 };
327 
328 template <typename T>
330 {
331  using type = T;
332  static constexpr bool value = true;
334 };
336 
338 
342 template <typename, typename = void>
343 struct can_get_memory_size_trait : std::false_type
344 {
345 };
346 
347 template <typename T>
349  void_t<decltype(&std::remove_reference<T>::type::getMemorySize)>>
350  : public can_get_memory_size_trait<decltype(&std::remove_reference<T>::type::getMemorySize)>
351 {
352  using type = T;
353  static constexpr bool value = true;
354 };
355 
356 template <typename T>
358 {
359 };
360 
361 template <typename T>
363 {
364 };
366 
372 template <typename T>
374 {
375  using type = T;
376  using trait =
378  static constexpr bool can_read = trait::value;
379  using rtype = typename trait::rtype;
380  static constexpr iarrays::ReadOperatorCodes code = trait::code;
385 };
386 
387 VTK_ABI_NAMESPACE_END
388 
389 } // detail
390 } // vtk
391 
392 #endif // vtkImplicitArrayTraits_h
@ value
Definition: vtkX3D.h:220
@ type
Definition: vtkX3D.h:516
ReadOperatorCodes
An enum for formalizing the different trait types accepted for defining a "readable" object.
typename make_void< Ts... >::type void_t
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
An intermediate trait for exposing a unified trait interface.
static constexpr iarrays::ReadOperatorCodes code
used to check whether the template type has a method named getMemorySize
An intermediate trait for exposing a unified trait interface.
An intermediate trait for exposing a unified trait interface.
static constexpr iarrays::ReadOperatorCodes code
An intermediate trait for exposing a unified trait interface.
used to check whether the template type has a method named mapComponent
used to check whether the template type has a method named map
used to check whether the template type has a method named mapTuple
A composite trait for handling all the different capabilities a "backend" to an implicit array can ha...
static constexpr iarrays::ReadOperatorCodes code
typename std::conditional< can_map_trait< T >::value, can_map_trait< T >, can_close_trait< T > >::type trait
A trait determining whether an object acts like a mono-variable integer closure.