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.")
38 template <
typename... Ts>
50 using type = std::false_type;
53 template <
typename... Ts>
54 struct IsListImpl<
vtkm::List<Ts...>>
56 using type = std::true_type;
60 using IsList =
typename vtkm::internal::IsListImpl<T>::type;
69 #define VTKM_IS_LIST(type) \
70 VTKM_STATIC_ASSERT_MSG((::vtkm::internal::IsList<type>::value), \
71 "Provided type is not a valid VTK-m list type.")
77 struct UniversalTypeTag
81 UniversalTypeTag() =
delete;
102 template <
typename... Ts>
103 struct ListSizeImpl<
vtkm::
List<Ts...>>
106 std::integral_constant<vtkm::IdComponent, static_cast<vtkm::IdComponent>(
sizeof...(Ts))>;
113 template <
typename List>
114 using ListSize =
typename detail::ListSizeImpl<List>::type;
119 template <
typename T,
template <
typename...>
class Target>
120 struct ListApplyImpl;
121 template <
typename... Ts,
template <
typename...>
class Target>
122 struct ListApplyImpl<
vtkm::
List<Ts...>, Target>
124 using type = Target<Ts...>;
127 template <
template <
typename...>
class Target>
137 template <typename List, template <typename...> class Target>
138 using
ListApply = typename detail::ListApplyImpl<List, Target>::type;
143 template <
typename... Ls>
144 struct ListAppendImpl;
147 struct ListAppendImpl<>
152 template <
typename L>
153 struct ListAppendImpl<L>
158 template <
typename... T0s,
typename... T1s>
165 template <
typename... T0s,
typename... T1s,
typename... T2s>
168 using type =
vtkm::List<T0s..., T1s..., T2s...>;
172 template <
typename... T0s,
typename... T1s,
typename... T2s,
typename... T3s>
173 struct ListAppendImpl<
vtkm::
List<T0s...>,
178 using type =
vtkm::List<T0s..., T1s..., T2s..., T3s...>;
182 template <
typename... T0s,
typename... T1s,
typename... T2s,
typename... T3s,
typename... T4s>
183 struct ListAppendImpl<
vtkm::
List<T0s...>,
189 using type =
vtkm::List<T0s..., T1s..., T2s..., T3s..., T4s...>;
193 template <
typename... T0s,
199 struct ListAppendImpl<
vtkm::
List<T0s...>,
206 using type =
vtkm::List<T0s..., T1s..., T2s..., T3s..., T4s..., T5s...>;
210 template <
typename... T0s,
217 struct ListAppendImpl<
vtkm::
List<T0s...>,
225 using type =
vtkm::List<T0s..., T1s..., T2s..., T3s..., T4s..., T5s..., T6s...>;
229 template <
typename... T0s,
237 struct ListAppendImpl<
vtkm::
List<T0s...>,
246 using type =
vtkm::List<T0s..., T1s..., T2s..., T3s..., T4s..., T5s..., T6s..., T7s...>;
250 template <
typename... T0s,
259 struct ListAppendImpl<
vtkm::
List<T0s...>,
269 using type =
typename ListAppendImpl<
270 vtkm::List<T0s..., T1s..., T2s..., T3s..., T4s..., T5s..., T6s..., T7s...>,
280 template <
typename... Lists>
281 using ListAppend =
typename detail::ListAppendImpl<Lists...>::type;
286 template <
typename T, vtkm::IdComponent N>
289 using type =
typename ListAppendImpl<
typename ListFillImpl<T, (N / 2)>::type,
290 typename ListFillImpl<T, (N - (N / 2))>::type>::type;
293 template <
typename T>
294 struct ListFillImpl<T, 1>
299 template <
typename T>
300 struct ListFillImpl<T, 0>
309 template <
typename T, vtkm::IdComponent N>
310 using ListFill =
typename detail::ListFillImpl<T, N>::type;
315 template <
typename T>
316 struct ListAtImplFunc;
318 template <
typename... VoidTypes>
319 struct ListAtImplFunc<
vtkm::
List<VoidTypes...>>
329 template <
typename T,
class... Other>
330 static T at(VoidTypes..., T*, Other...);
333 template <
typename T, vtkm::IdComponent Index>
349 template <
typename List, vtkm::IdComponent Index>
350 using ListAt =
typename detail::ListAtImpl<List, Index>::type;
356 struct FindFirstOfType;
359 template <vtkm::IdComponent NumSearched,
typename Target>
360 struct FindFirstOfType<NumSearched, Target> : std::integral_constant<vtkm::IdComponent, -1>
365 template <
bool NextIsTarget,
vtkm::IdComponent NumSearched,
typename Target,
typename... Remaining>
366 struct FindFirstOfCheckHead;
369 struct FindFirstOfCheckHead<true, NumSearched, Target, Ts...>
370 : std::integral_constant<vtkm::IdComponent, NumSearched>
374 template <
vtkm::IdComponent NumSearched,
typename Target,
typename Next,
typename... Remaining>
375 struct FindFirstOfCheckHead<false, NumSearched, Target, Next, Remaining...>
376 : FindFirstOfCheckHead<std::is_same<Target, Next>::value, NumSearched + 1, Target, Remaining...>
381 template <vtkm::IdComponent NumSearched,
typename Target>
382 struct FindFirstOfCheckHead<false, NumSearched, Target>
383 : std::integral_constant<vtkm::IdComponent, -1>
387 template <
vtkm::IdComponent NumSearched,
typename Target,
typename Next,
typename... Remaining>
388 struct FindFirstOfType<NumSearched, Target, Next, Remaining...>
389 : FindFirstOfCheckHead<std::is_same<Target, Next>::value, NumSearched, Target, Remaining...>
394 template <
bool OneInFirst4Matches,
vtkm::IdComponent NumSearched,
typename Target,
typename... Ts>
395 struct FindFirstOfSplit4;
404 struct FindFirstOfSplit4<true, NumSearched, Target, T0, T1, T2, T3, Ts...>
405 : FindFirstOfCheckHead<std::is_same<Target, T0>::value, NumSearched, Target, T1, T2, T3>
417 struct FindFirstOfSplit4<false, NumSearched, Target, T0, T1, T2, T3, T4, Ts...>
418 : FindFirstOfCheckHead<std::is_same<Target, T4>::value, NumSearched + 4, Target, Ts...>
431 struct FindFirstOfType<NumSearched, Target, T0, T1, T2, T3, T4, T5, Ts...>
432 : FindFirstOfSplit4<(std::is_same<Target, T0>::value || std::is_same<Target, T1>::value ||
433 std::is_same<Target, T2>::value || std::is_same<Target, T3>::value),
447 template <
bool OneInFirst8Matches,
vtkm::IdComponent NumSearched,
typename Target,
typename... Ts>
448 struct FindFirstOfSplit8;
461 struct FindFirstOfSplit8<true, NumSearched, Target, T0, T1, T2, T3, T4, T5, T6, T7, Ts...>
462 : FindFirstOfSplit4<(std::is_same<Target, T0>::value || std::is_same<Target, T1>::value ||
463 std::is_same<Target, T2>::value || std::is_same<Target, T3>::value),
488 struct FindFirstOfSplit8<false, NumSearched, Target, T0, T1, T2, T3, T4, T5, T6, T7, Ts...>
489 : FindFirstOfType<NumSearched + 8, Target, Ts...>
508 struct FindFirstOfType<NumSearched, Target, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, Ts...>
509 : FindFirstOfSplit8<(std::is_same<Target, T0>::value || std::is_same<Target, T1>::value ||
510 std::is_same<Target, T2>::value || std::is_same<Target, T3>::value ||
511 std::is_same<Target, T4>::value || std::is_same<Target, T5>::value ||
512 std::is_same<Target, T6>::value || std::is_same<Target, T7>::value),
531 template <
typename List,
typename Target>
532 struct ListIndexOfImpl;
533 template <
typename... Ts,
typename Target>
534 struct ListIndexOfImpl<
vtkm::
List<Ts...>, Target>
536 using type = std::integral_constant<
vtkm::IdComponent, FindFirstOfType<0, Target, Ts...>::value>;
538 template <
typename Target>
542 "Cannot get indices in a universal list.");
552 template <
typename List,
typename T>
553 using ListIndexOf =
typename detail::ListIndexOfImpl<List, T>::type;
558 template <
typename List,
typename T>
564 template <
typename T>
567 using type = std::true_type;
576 template <
typename List,
typename T>
577 using ListHas =
typename detail::ListHasImpl<List, T>::type;
582 template <
typename T,
template <
typename>
class Target>
583 struct ListTransformImpl;
584 template <
typename... Ts,
template <
typename>
class Target>
585 struct ListTransformImpl<
vtkm::
List<Ts...>, Target>
590 template <
template <
typename>
class Target>
597 template <typename List, template <typename> class Transform>
598 using
ListTransform = typename detail::ListTransformImpl<List, Transform>::type;
603 #if defined(VTKM_MSVC) && (_MSC_VER < 1920)
606 template <
typename Passed,
612 struct ListRemoveIfCheckNext;
614 template <
typename Passed,
typename Rest,
template <
typename>
class Predicate>
615 struct ListRemoveIfGetNext;
617 template <
typename Passed,
typename Next,
typename Rest,
template <
typename>
class Predicate>
618 struct ListRemoveIfCheckNext<Passed, Next, true, Rest, Predicate>
620 using type =
typename ListRemoveIfGetNext<Passed, Rest, Predicate>::type;
623 template <
typename... PassedTs,
typename Next,
typename Rest,
template <
typename>
class Predicate>
624 struct ListRemoveIfCheckNext<
vtkm::
List<PassedTs...>, Next, false, Rest, Predicate>
626 using type =
typename ListRemoveIfGetNext<
vtkm::List<PassedTs..., Next>, Rest, Predicate>::type;
629 template <
typename Passed,
typename Next,
typename... RestTs,
template <
typename>
class Predicate>
630 struct ListRemoveIfGetNext<Passed,
vtkm::
List<Next, RestTs...>, Predicate>
632 using type =
typename ListRemoveIfCheckNext<Passed,
634 Predicate<Next>::value,
639 template <
typename Passed,
template <
typename>
class Predicate>
640 struct ListRemoveIfGetNext<Passed,
vtkm::
List<>, Predicate>
645 template <
typename L,
template <
typename>
class Predicate>
646 struct ListRemoveIfImpl
648 using type =
typename ListRemoveIfGetNext<vtkm::List<>, L, Predicate>::type;
653 template <
typename L,
template <
typename>
class Predicate>
654 struct ListRemoveIfImpl;
656 template <
typename... Ts,
template <
typename>
class Predicate>
657 struct ListRemoveIfImpl<
vtkm::
List<Ts...>, Predicate>
659 using type =
typename ListAppendImpl<
679 template <
typename List,
template <
typename>
class Predicate>
680 using ListRemoveIf =
typename detail::ListRemoveIfImpl<List, Predicate>::type;
685 template <
typename List1,
typename List2>
686 struct ListIntersectImpl
688 template <
typename T>
697 template <
typename List1>
702 template <
typename List2>
717 template <
typename List1,
typename List2>
718 using ListIntersect =
typename detail::ListIntersectImpl<List1, List2>::type;
724 template <
typename Functor,
typename... Ts,
typename... Args>
728 "Cannot call ListFor on vtkm::ListUniversal.");
729 auto init_list = { (f(Ts{}, std::forward<Args>(args)...),
false)... };
732 template <
typename Functor,
typename... Args>
741 template <
typename List1,
typename List2>
742 struct ListCrossImpl;
744 template <
typename... T0s,
typename... T1s>
747 template <
typename T>
762 template <
typename List1,
typename List2>
763 using ListCross =
typename detail::ListCrossImpl<List1, List2>::type;
768 template <
typename L,
template <
typename T1,
typename T2>
class Operator,
typename Result>
769 struct ListReduceImpl;
771 template <
template <
typename T1,
typename T2>
class Operator,
typename Result>
772 struct ListReduceImpl<
vtkm::
List<>, Operator, Result>
777 template <
typename T0,
779 template <
typename O1,
typename O2>
782 struct ListReduceImpl<
vtkm::
List<T0, Ts...>, Operator, Result>
784 using type =
typename ListReduceImpl<
vtkm::List<Ts...>, Operator, Operator<Result, T0>>::type;
787 template <
typename T0,
797 template <
typename O1,
typename O2>
800 struct ListReduceImpl<
vtkm::
List<T0, T1, T2, T3, T4, T5, T6, T7, T8, Ts...>, Operator, Result>
802 using type =
typename ListReduceImpl<
805 typename ListReduceImpl<vtkm::List<T0, T1, T2, T3, T4, T5, T6, T7>, Operator, Result>::type>::
818 template <
typename List,
template <
typename T1,
typename T2>
class Operator,
typename Initial>
819 using ListReduce =
typename detail::ListReduceImpl<List, Operator, Initial>::type;
841 template <
typename List,
template <
typename>
class Predicate = vtkm::internal::meta::Identity>
866 template <
typename List,
template <
typename>
class Predicate = vtkm::internal::meta::Identity>
870 #undef VTKM_CHECK_LIST_SIZE
874 #endif //vtk_m_List_h