26 #define VTKM_CHECK_LIST_SIZE(size) \
27 static_assert((size) <= 512, \
28 "A vtkm::List with more than 512 elements is not supported." \
29 " A list this long is problematic for compilers." \
30 " Compilers often have a recursive template instantiation limit of around 1024," \
31 " so operations on lists this large can lead to confusing and misleading errors.")
33 template <
typename... Ts>
45 using type = std::false_type;
48 template <
typename... Ts>
49 struct IsListImpl<
vtkm::List<Ts...>>
51 using type = std::true_type;
55 using IsList =
typename vtkm::internal::IsListImpl<T>::type;
64 #define VTKM_IS_LIST(type) \
65 VTKM_STATIC_ASSERT_MSG((::vtkm::internal::IsList<type>::value), \
66 "Provided type is not a valid VTK-m list type.")
72 struct UniversalTypeTag
76 UniversalTypeTag() =
delete;
96 template <
typename... Ts>
97 struct ListSizeImpl<
vtkm::
List<Ts...>>
100 std::integral_constant<vtkm::IdComponent, static_cast<vtkm::IdComponent>(
sizeof...(Ts))>;
107 template <
typename List>
108 using ListSize =
typename detail::ListSizeImpl<List>::type;
113 template <
typename T,
template <
typename...>
class Target>
114 struct ListApplyImpl;
115 template <
typename... Ts,
template <
typename...>
class Target>
116 struct ListApplyImpl<
vtkm::
List<Ts...>, Target>
118 using type = Target<Ts...>;
121 template <
template <
typename...>
class Target>
131 template <typename List, template <typename...> class Target>
132 using
ListApply = typename detail::ListApplyImpl<List, Target>::type;
137 template <
typename... Ls>
138 struct ListAppendImpl;
141 struct ListAppendImpl<>
146 template <
typename L>
147 struct ListAppendImpl<L>
152 template <
typename... T0s,
typename... T1s>
159 template <
typename... T0s,
typename... T1s,
typename... T2s>
162 using type =
vtkm::List<T0s..., T1s..., T2s...>;
166 template <
typename... T0s,
typename... T1s,
typename... T2s,
typename... T3s>
167 struct ListAppendImpl<
vtkm::
List<T0s...>,
172 using type =
vtkm::List<T0s..., T1s..., T2s..., T3s...>;
176 template <
typename... T0s,
typename... T1s,
typename... T2s,
typename... T3s,
typename... T4s>
177 struct ListAppendImpl<
vtkm::
List<T0s...>,
183 using type =
vtkm::List<T0s..., T1s..., T2s..., T3s..., T4s...>;
187 template <
typename... T0s,
193 struct ListAppendImpl<
vtkm::
List<T0s...>,
200 using type =
vtkm::List<T0s..., T1s..., T2s..., T3s..., T4s..., T5s...>;
204 template <
typename... T0s,
211 struct ListAppendImpl<
vtkm::
List<T0s...>,
219 using type =
vtkm::List<T0s..., T1s..., T2s..., T3s..., T4s..., T5s..., T6s...>;
223 template <
typename... T0s,
231 struct ListAppendImpl<
vtkm::
List<T0s...>,
240 using type =
vtkm::List<T0s..., T1s..., T2s..., T3s..., T4s..., T5s..., T6s..., T7s...>;
244 template <
typename... T0s,
253 struct ListAppendImpl<
vtkm::
List<T0s...>,
263 using type =
typename ListAppendImpl<
264 vtkm::List<T0s..., T1s..., T2s..., T3s..., T4s..., T5s..., T6s..., T7s...>,
274 template <
typename... Lists>
275 using ListAppend =
typename detail::ListAppendImpl<Lists...>::type;
280 template <
typename T, vtkm::IdComponent N>
283 using type =
typename ListAppendImpl<
typename ListFillImpl<T, (N / 2)>::type,
284 typename ListFillImpl<T, (N - (N / 2))>::type>::type;
287 template <
typename T>
288 struct ListFillImpl<T, 1>
293 template <
typename T>
294 struct ListFillImpl<T, 0>
303 template <
typename T, vtkm::IdComponent N>
304 using ListFill =
typename detail::ListFillImpl<T, N>::type;
309 template <
typename T>
310 struct ListAtImplFunc;
312 template <
typename... VoidTypes>
313 struct ListAtImplFunc<
vtkm::
List<VoidTypes...>>
323 template <
typename T,
class... Other>
324 static T at(VoidTypes..., T*, Other...);
327 template <
typename T, vtkm::IdComponent Index>
343 template <
typename List, vtkm::IdComponent Index>
344 using ListAt =
typename detail::ListAtImpl<List, Index>::type;
350 struct FindFirstOfType;
353 template <vtkm::IdComponent NumSearched,
typename Target>
354 struct FindFirstOfType<NumSearched, Target> : std::integral_constant<vtkm::IdComponent, -1>
359 template <
bool NextIsTarget,
vtkm::IdComponent NumSearched,
typename Target,
typename... Remaining>
360 struct FindFirstOfCheckHead;
363 struct FindFirstOfCheckHead<true, NumSearched, Target, Ts...>
364 : std::integral_constant<vtkm::IdComponent, NumSearched>
368 template <
vtkm::IdComponent NumSearched,
typename Target,
typename Next,
typename... Remaining>
369 struct FindFirstOfCheckHead<false, NumSearched, Target, Next, Remaining...>
370 : FindFirstOfCheckHead<std::is_same<Target, Next>::value, NumSearched + 1, Target, Remaining...>
375 template <vtkm::IdComponent NumSearched,
typename Target>
376 struct FindFirstOfCheckHead<false, NumSearched, Target>
377 : std::integral_constant<vtkm::IdComponent, -1>
381 template <
vtkm::IdComponent NumSearched,
typename Target,
typename Next,
typename... Remaining>
382 struct FindFirstOfType<NumSearched, Target, Next, Remaining...>
383 : FindFirstOfCheckHead<std::is_same<Target, Next>::value, NumSearched, Target, Remaining...>
388 template <
bool OneInFirst4Matches,
vtkm::IdComponent NumSearched,
typename Target,
typename... Ts>
389 struct FindFirstOfSplit4;
398 struct FindFirstOfSplit4<true, NumSearched, Target, T0, T1, T2, T3, Ts...>
399 : FindFirstOfCheckHead<std::is_same<Target, T0>::value, NumSearched, Target, T1, T2, T3>
411 struct FindFirstOfSplit4<false, NumSearched, Target, T0, T1, T2, T3, T4, Ts...>
412 : FindFirstOfCheckHead<std::is_same<Target, T4>::value, NumSearched + 4, Target, Ts...>
425 struct FindFirstOfType<NumSearched, Target, T0, T1, T2, T3, T4, T5, Ts...>
426 : FindFirstOfSplit4<(std::is_same<Target, T0>::value || std::is_same<Target, T1>::value ||
427 std::is_same<Target, T2>::value || std::is_same<Target, T3>::value),
441 template <
bool OneInFirst8Matches,
vtkm::IdComponent NumSearched,
typename Target,
typename... Ts>
442 struct FindFirstOfSplit8;
455 struct FindFirstOfSplit8<true, NumSearched, Target, T0, T1, T2, T3, T4, T5, T6, T7, Ts...>
456 : FindFirstOfSplit4<(std::is_same<Target, T0>::value || std::is_same<Target, T1>::value ||
457 std::is_same<Target, T2>::value || std::is_same<Target, T3>::value),
482 struct FindFirstOfSplit8<false, NumSearched, Target, T0, T1, T2, T3, T4, T5, T6, T7, Ts...>
483 : FindFirstOfType<NumSearched + 8, Target, Ts...>
502 struct FindFirstOfType<NumSearched, Target, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, Ts...>
503 : FindFirstOfSplit8<(std::is_same<Target, T0>::value || std::is_same<Target, T1>::value ||
504 std::is_same<Target, T2>::value || std::is_same<Target, T3>::value ||
505 std::is_same<Target, T4>::value || std::is_same<Target, T5>::value ||
506 std::is_same<Target, T6>::value || std::is_same<Target, T7>::value),
525 template <
typename List,
typename Target>
526 struct ListIndexOfImpl;
527 template <
typename... Ts,
typename Target>
528 struct ListIndexOfImpl<
vtkm::
List<Ts...>, Target>
530 using type = std::integral_constant<
vtkm::IdComponent, FindFirstOfType<0, Target, Ts...>::value>;
532 template <
typename Target>
536 "Cannot get indices in a universal list.");
546 template <
typename List,
typename T>
547 using ListIndexOf =
typename detail::ListIndexOfImpl<List, T>::type;
552 template <
typename List,
typename T>
558 template <
typename T>
561 using type = std::true_type;
570 template <
typename List,
typename T>
571 using ListHas =
typename detail::ListHasImpl<List, T>::type;
576 template <
typename T,
template <
typename>
class Target>
577 struct ListTransformImpl;
578 template <
typename... Ts,
template <
typename>
class Target>
579 struct ListTransformImpl<
vtkm::
List<Ts...>, Target>
584 template <
template <
typename>
class Target>
591 template <typename List, template <typename> class Transform>
592 using
ListTransform = typename detail::ListTransformImpl<List, Transform>::type;
597 #if defined(VTKM_MSVC) && (_MSC_VER < 1920)
600 template <
typename Passed,
606 struct ListRemoveIfCheckNext;
608 template <
typename Passed,
typename Rest,
template <
typename>
class Predicate>
609 struct ListRemoveIfGetNext;
611 template <
typename Passed,
typename Next,
typename Rest,
template <
typename>
class Predicate>
612 struct ListRemoveIfCheckNext<Passed, Next, true, Rest, Predicate>
614 using type =
typename ListRemoveIfGetNext<Passed, Rest, Predicate>::type;
617 template <
typename... PassedTs,
typename Next,
typename Rest,
template <
typename>
class Predicate>
618 struct ListRemoveIfCheckNext<
vtkm::
List<PassedTs...>, Next, false, Rest, Predicate>
620 using type =
typename ListRemoveIfGetNext<
vtkm::List<PassedTs..., Next>, Rest, Predicate>::type;
623 template <
typename Passed,
typename Next,
typename... RestTs,
template <
typename>
class Predicate>
624 struct ListRemoveIfGetNext<Passed,
vtkm::
List<Next, RestTs...>, Predicate>
626 using type =
typename ListRemoveIfCheckNext<Passed,
628 Predicate<Next>::value,
633 template <
typename Passed,
template <
typename>
class Predicate>
634 struct ListRemoveIfGetNext<Passed,
vtkm::
List<>, Predicate>
639 template <
typename L,
template <
typename>
class Predicate>
640 struct ListRemoveIfImpl
642 using type =
typename ListRemoveIfGetNext<vtkm::List<>, L, Predicate>::type;
647 template <
typename L,
template <
typename>
class Predicate>
648 struct ListRemoveIfImpl;
650 template <
typename... Ts,
template <
typename>
class Predicate>
651 struct ListRemoveIfImpl<
vtkm::
List<Ts...>, Predicate>
653 using type =
typename ListAppendImpl<
673 template <
typename List,
template <
typename>
class Predicate>
674 using ListRemoveIf =
typename detail::ListRemoveIfImpl<List, Predicate>::type;
679 template <
typename List1,
typename List2>
680 struct ListIntersectImpl
682 template <
typename T>
691 template <
typename List1>
696 template <
typename List2>
711 template <
typename List1,
typename List2>
712 using ListIntersect =
typename detail::ListIntersectImpl<List1, List2>::type;
719 template <
typename Functor,
typename... Ts,
typename... Args>
723 "Cannot call ListFor on vtkm::ListUniversal.");
724 auto init_list = { (f(Ts{}, std::forward<Args>(args)...),
false)... };
727 template <
typename Functor,
typename... Args>
737 template <
typename List1,
typename List2>
738 struct ListCrossImpl;
740 template <
typename... T0s,
typename... T1s>
743 template <
typename T>
758 template <
typename List1,
typename List2>
759 using ListCross =
typename detail::ListCrossImpl<List1, List2>::type;
764 template <
typename L,
template <
typename T1,
typename T2>
class Operator,
typename Result>
765 struct ListReduceImpl;
767 template <
template <
typename T1,
typename T2>
class Operator,
typename Result>
768 struct ListReduceImpl<
vtkm::
List<>, Operator, Result>
773 template <
typename T0,
775 template <
typename O1,
typename O2>
778 struct ListReduceImpl<
vtkm::
List<T0, Ts...>, Operator, Result>
780 using type =
typename ListReduceImpl<
vtkm::List<Ts...>, Operator, Operator<Result, T0>>::type;
783 template <
typename T0,
793 template <
typename O1,
typename O2>
796 struct ListReduceImpl<
vtkm::
List<T0, T1, T2, T3, T4, T5, T6, T7, T8, Ts...>, Operator, Result>
798 using type =
typename ListReduceImpl<
801 typename ListReduceImpl<vtkm::List<T0, T1, T2, T3, T4, T5, T6, T7>, Operator, Result>::type>::
814 template <
typename List,
template <
typename T1,
typename T2>
class Operator,
typename Initial>
815 using ListReduce =
typename detail::ListReduceImpl<List, Operator, Initial>::type;
837 template <
typename List,
template <
typename>
class Predicate = vtkm::internal::meta::Identity>
862 template <
typename List,
template <
typename>
class Predicate = vtkm::internal::meta::Identity>
866 #undef VTKM_CHECK_LIST_SIZE
870 #endif //vtk_m_List_h