23
23
24
24
#include " pmacc/meta/accessors/Identity.hpp"
25
25
26
+ #include < boost/mp11.hpp>
26
27
#include < boost/mpl/apply.hpp>
27
- #include < boost/mpl/begin_end.hpp>
28
- #include < boost/mpl/deref.hpp>
28
+ #include < boost/mpl/copy.hpp>
29
29
#include < boost/mpl/transform.hpp>
30
30
31
31
#include < type_traits>
32
- #include < utility>
33
-
34
32
35
33
namespace pmacc
36
34
{
37
35
namespace meta
38
36
{
39
37
namespace detail
40
38
{
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;
88
41
} // namespace detail
89
42
90
43
/* * Compile-Time for each for Boost::MPL Type Lists
@@ -110,36 +63,19 @@ namespace pmacc
110
63
template <typename T_MPLSeq, typename T_Functor, typename T_Accessor = meta::accessors::Identity<>>
111
64
struct ForEach
112
65
{
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>;
117
67
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;
125
71
126
- /* this functor does nothing */
127
- using Functor = detail::CallFunctorOfIterator<end, end>;
72
+ using SolvedFunctors = boost::mp11::mp_transform<ReplacePlaceholder, List>;
128
73
129
74
PMACC_NO_NVCC_HDWARNING
130
75
template <typename ... T_Types>
131
76
HDINLINE void operator ()(T_Types&&... ts) const
132
77
{
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)...); });
143
79
}
144
80
};
145
81
0 commit comments