VTK  9.3.20241006
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
35namespace vtk
36{
37namespace detail
38{
39
40VTK_ABI_NAMESPACE_BEGIN
41
42template <typename... Ts>
44{
45 using type = void;
46};
47
48template <typename... Ts>
49using void_t = typename make_void<Ts...>::type;
50
52
56template <typename, typename = void>
57struct has_map_trait : std::false_type
58{
59};
60
61template <typename T>
62struct 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
68template <typename T>
70{
71};
72
73template <typename T>
74struct has_map_trait<const T> : public has_map_trait<T>
75{
76};
77
78template <typename R, typename T, typename Arg>
79struct has_map_trait<R (T::*)(Arg) const> : public has_map_trait<R(Arg)>
80{
81};
82
83template <typename R, typename Arg>
84struct 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
97template <typename, typename = void>
98struct is_closure_trait : std::false_type
99{
100};
101
102template <typename Closure>
103struct is_closure_trait<Closure, void_t<decltype(&Closure::operator())>>
104 : public is_closure_trait<decltype(&Closure::operator())>
105{
106 using type = Closure;
107};
108
109template <typename Closure>
111{
112};
113
114template <typename Closure>
115struct is_closure_trait<const Closure> : public is_closure_trait<Closure>
116{
117};
118
119template <typename Closure>
121{
122};
123
124template <typename Closure, typename R, typename Arg>
125struct is_closure_trait<R (Closure::*)(Arg) const> : public is_closure_trait<R(Arg)>
126{
127};
128
129template <typename R, typename Arg>
130struct is_closure_trait<R (*)(Arg)> : public is_closure_trait<R(Arg)>
131{
132};
133
134template <typename R, typename Arg>
135struct 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
148template <typename, typename = void>
149struct has_map_tuple_trait : std::false_type
150{
151};
152
153template <typename T>
154struct 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
160template <typename T>
162{
163};
164
165template <typename T>
166struct has_map_tuple_trait<const T> : public has_map_tuple_trait<T>
167{
168};
169
170template <typename T, typename ArgIdx, typename ArgTup>
171struct has_map_tuple_trait<void (T::*)(ArgIdx, ArgTup*) const>
172 : public has_map_tuple_trait<void(ArgIdx, ArgTup*)>
173{
174};
175
176template <typename ArgIdx, typename ArgTup>
177struct 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
190template <typename, typename = void>
191struct has_map_component_trait : std::false_type
192{
193};
194
195template <typename T>
196struct 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
202template <typename T>
204{
205};
206
207template <typename T>
209{
210};
211
212template <typename R, typename T, typename ArgTupIdx, typename ArgCompIdx>
213struct has_map_component_trait<R (T::*)(ArgTupIdx, ArgCompIdx) const>
214 : public has_map_component_trait<R(ArgTupIdx, ArgCompIdx)>
215{
216};
217
218template <typename R, typename ArgTupIdx, typename ArgCompIdx>
219struct 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
230namespace iarrays
231{
238{
241 CLOSURE
243}
244
246
250template <typename T, typename = void>
252{
253 using type = T;
254 static constexpr bool value = false;
255 using rtype = void;
257};
258
259template <typename T>
260struct can_map_trait<T, void_t<typename has_map_trait<T>::rtype>>
261{
262 using type = T;
263 static constexpr bool value = true;
266};
268
270
274template <typename T, typename = void>
276{
277 using type = T;
278 static constexpr bool value = false;
279 using rtype = void;
281};
282
283template <typename T>
285{
286 using type = T;
287 static constexpr bool value = true;
290};
292
294
298template <typename T, typename = void>
300{
301 using type = T;
302 static constexpr bool value = false;
303 using rtype = void;
304};
305
306template <typename T>
308{
309 using type = T;
310 static constexpr bool value = true;
312};
314
316
320template <typename T, typename = void>
322{
323 using type = T;
324 static constexpr bool value = false;
325 using rtype = void;
326};
327
328template <typename T>
330{
331 using type = T;
332 static constexpr bool value = true;
334};
336
338
342template <typename, typename = void>
343struct can_get_memory_size_trait : std::false_type
344{
345};
346
347template <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
356template <typename T>
358{
359};
360
361template <typename T>
363{
364};
366
372template <typename T>
374{
375 using type = T;
376 using trait =
377 typename std::conditional<can_map_trait<T>::value, can_map_trait<T>, can_close_trait<T>>::type;
378 static constexpr bool can_read = trait::value;
379 using rtype = typename trait::rtype;
380 static constexpr iarrays::ReadOperatorCodes code = trait::code;
381 static constexpr bool default_constructible = std::is_default_constructible<T>::value;
385};
386
387VTK_ABI_NAMESPACE_END
388
389} // detail
390} // vtk
391
392#endif // vtkImplicitArrayTraits_h
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.