OGS
SerialExecutor.h
Go to the documentation of this file.
1
13#pragma once
14
15#include <cassert>
16#include <cstddef>
17#include <utility>
18#include <vector>
19
20namespace NumLib
21{
23{
47 template <typename F, typename C, typename... Args_>
48 static void executeDereferenced(F const& f, C const& c, Args_&&... args)
49 {
50 for (std::size_t i = 0; i < c.size(); i++)
51 {
52 f(i, *c[i], std::forward<Args_>(args)...);
53 }
54 }
55
69 template <typename Container, typename Object, typename Method,
70 typename... Args>
71 static void executeMemberDereferenced(Object& object, Method method,
72 Container const& container,
73 Args&&... args)
74 {
75 for (std::size_t i = 0; i < container.size(); i++)
76 {
77 (object.*method)(i, *container[i], std::forward<Args>(args)...);
78 }
79 }
80
96 template <typename Container, typename Object, typename Method,
97 typename... Args>
99 Object& object, Method method, Container const& container,
100 std::vector<std::size_t> const& active_container_ids, Args&&... args)
101 {
102 if (active_container_ids.empty())
103 {
104 executeMemberDereferenced(object, method, container,
105 std::forward<Args>(args)...);
106 return;
107 }
108
109 for (auto const id : active_container_ids)
110 {
111 (object.*method)(id, *container[id], std::forward<Args>(args)...);
112 }
113 }
114
126 template <typename Container, typename Method, typename... Args>
127 static void executeMemberOnDereferenced(Method method,
128 Container const& container,
129 Args&&... args)
130 {
131 for (std::size_t i = 0; i < container.size(); i++)
132 {
133 ((*container[i]).*method)(i, std::forward<Args>(args)...);
134 }
135 }
136
151 template <typename Container, typename Method, typename... Args>
153 Method method, Container const& container,
154 std::vector<std::size_t> const& active_container_ids, Args&&... args)
155 {
156 if (active_container_ids.empty())
157 {
158 executeMemberOnDereferenced(method, container,
159 std::forward<Args>(args)...);
160 return;
161 }
162
163 for (auto const id : active_container_ids)
164 {
165 ((*container[id]).*method)(id, std::forward<Args>(args)...);
166 }
167 }
168
186 template <typename F, typename C, typename Data, typename... Args_>
187 static void transformDereferenced(F const& f, C const& c, Data& data,
188 Args_&&... args)
189 {
190 assert(c.size() == data.size());
191
192 for (std::size_t i = 0; i < c.size(); i++)
193 {
194 data[i] = f(i, *c[i], std::forward<Args_>(args)...);
195 }
196 }
197};
198
199} // namespace NumLib
static void executeSelectedMemberOnDereferenced(Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
static void transformDereferenced(F const &f, C const &c, Data &data, Args_ &&... args)
static void executeSelectedMemberDereferenced(Object &object, Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
static void executeMemberOnDereferenced(Method method, Container const &container, Args &&... args)
static void executeMemberDereferenced(Object &object, Method method, Container const &container, Args &&... args)
static void executeDereferenced(F const &f, C const &c, Args_ &&... args)