2323
2424#include " pmacc/meta/accessors/Identity.hpp"
2525
26+ #include < boost/mp11.hpp>
2627#include < boost/mpl/apply.hpp>
27- #include < boost/mpl/begin_end.hpp>
28- #include < boost/mpl/deref.hpp>
28+ #include < boost/mpl/copy.hpp>
2929#include < boost/mpl/transform.hpp>
3030
3131#include < type_traits>
32- #include < utility>
33-
3432
3533namespace pmacc
3634{
3735 namespace meta
3836 {
3937 namespace detail
4038 {
41- /* * call the functor were itBegin points to
42- *
43- * @tparam itBegin iterator to an element in a mpl sequence
44- * @tparam itEnd iterator to the end of a mpl sequence
45- * @tparam isEnd true if itBegin == itEnd, else false
46- */
47- template <typename itBegin, typename itEnd, bool isEnd = std::is_same<itBegin, itEnd>::value>
48- struct CallFunctorOfIterator
49- {
50- using nextIt = typename boost::mpl::next<itBegin>::type;
51- using Functor = typename boost::mpl::deref<itBegin>::type;
52- using NextCall = CallFunctorOfIterator<nextIt, itEnd>;
53-
54- PMACC_NO_NVCC_HDWARNING
55- template <typename ... T_Types>
56- HDINLINE void operator ()(T_Types&&... ts) const
57- {
58- Functor ()(std::forward<T_Types>(ts)...);
59- NextCall ()(ts...);
60- }
61-
62- PMACC_NO_NVCC_HDWARNING
63- template <typename ... T_Types>
64- HDINLINE void operator ()(T_Types&&... ts)
65- {
66- Functor ()(std::forward<T_Types>(ts)...);
67- NextCall ()(ts...);
68- }
69- };
70-
71- /* * Recursion end of ForEach */
72- template <typename itBegin, typename itEnd>
73- struct CallFunctorOfIterator <itBegin, itEnd, true >
74- {
75- PMACC_NO_NVCC_HDWARNING
76- template <typename ... T_Types>
77- HDINLINE void operator ()(T_Types&&...) const
78- {
79- }
80-
81- PMACC_NO_NVCC_HDWARNING
82- template <typename ... T_Types>
83- HDINLINE void operator ()(T_Types&&...)
84- {
85- }
86- };
87-
39+ template <typename Seq>
40+ using SeqToList = typename boost::mpl::copy<Seq, boost::mpl::back_inserter<boost::mp11::mp_list<>>>::type;
8841 } // namespace detail
8942
9043 /* * Compile-Time for each for Boost::MPL Type Lists
@@ -110,36 +63,19 @@ namespace pmacc
11063 template <typename T_MPLSeq, typename T_Functor, typename T_Accessor = meta::accessors::Identity<>>
11164 struct ForEach
11265 {
113- template <typename X>
114- struct ReplacePlaceholder : bmpl::apply1<T_Functor, typename bmpl::apply1<T_Accessor, X>::type>
115- {
116- };
66+ using List = detail::SeqToList<T_MPLSeq>;
11767
118- using SolvedFunctors = typename bmpl::transform<T_MPLSeq, ReplacePlaceholder<bmpl::_1>>::type;
119-
120- using begin = typename boost::mpl::begin<SolvedFunctors>::type;
121- using end = typename boost::mpl::end<SolvedFunctors>::type;
122-
123-
124- using NextCall = detail::CallFunctorOfIterator<begin, end>;
68+ template <typename X>
69+ using ReplacePlaceholder =
70+ typename bmpl::apply1<T_Functor, typename bmpl::apply1<T_Accessor, X>::type>::type;
12571
126- /* this functor does nothing */
127- using Functor = detail::CallFunctorOfIterator<end, end>;
72+ using SolvedFunctors = boost::mp11::mp_transform<ReplacePlaceholder, List>;
12873
12974 PMACC_NO_NVCC_HDWARNING
13075 template <typename ... T_Types>
13176 HDINLINE void operator ()(T_Types&&... ts) const
13277 {
133- Functor ()(std::forward<T_Types>(ts)...);
134- NextCall ()(ts...);
135- }
136-
137- PMACC_NO_NVCC_HDWARNING
138- template <typename ... T_Types>
139- HDINLINE void operator ()(T_Types&&... ts)
140- {
141- Functor ()(std::forward<T_Types>(ts)...);
142- NextCall ()(ts...);
78+ boost::mp11::mp_for_each<SolvedFunctors>([&](auto functor) { functor (std::forward<T_Types>(ts)...); });
14379 }
14480 };
14581
0 commit comments