@@ -32,7 +32,8 @@ template <typename ValueType, typename ApplyFunction,
3232 ApplyFunction, ValueType>::value &&
3333 std::is_same<void , ApplyType>::value,
3434 int >::type = 0 >
35- void async_apply (const std::vector<ValueType> &xs, const ApplyFunction &f) {
35+ inline void async_apply (const std::vector<ValueType> &xs,
36+ const ApplyFunction &f) {
3637 std::vector<std::future<void >> futures;
3738 for (const auto &x : xs) {
3839 futures.emplace_back (async_safe (f, x));
@@ -49,7 +50,8 @@ template <typename ValueType, typename ApplyFunction,
4950 ApplyFunction, ValueType>::value &&
5051 !std::is_same<void , ApplyType>::value,
5152 int >::type = 0 >
52- auto async_apply (const std::vector<ValueType> &xs, const ApplyFunction &f) {
53+ inline auto async_apply (const std::vector<ValueType> &xs,
54+ const ApplyFunction &f) {
5355 std::vector<std::future<ApplyType>> futures;
5456 for (const auto &x : xs) {
5557 futures.emplace_back (async_safe (f, x));
@@ -62,6 +64,92 @@ auto async_apply(const std::vector<ValueType> &xs, const ApplyFunction &f) {
6264 return output;
6365}
6466
67+ // Map
68+
69+ template <
70+ template <typename ...> class Map , typename KeyType, typename ValueType,
71+ typename ApplyFunction,
72+ typename ApplyType = typename details::key_value_apply_result<
73+ ApplyFunction, KeyType, ValueType>::type,
74+ typename std::enable_if<details::is_valid_key_value_apply_function<
75+ ApplyFunction, KeyType, ValueType>::value &&
76+ std::is_same<void , ApplyType>::value,
77+ int >::type = 0 >
78+ inline void async_apply (const Map<KeyType, ValueType> &map, ApplyFunction &&f) {
79+ std::vector<std::future<void >> futures;
80+ for (const auto &pair : map) {
81+ futures.emplace_back (async_safe (f, pair.first , pair.second ));
82+ }
83+ for (auto &f : futures) {
84+ f.get ();
85+ }
86+ }
87+
88+ template <
89+ template <typename ...> class Map , typename KeyType, typename ValueType,
90+ typename ApplyFunction,
91+ typename ApplyType = typename details::key_value_apply_result<
92+ ApplyFunction, KeyType, ValueType>::type,
93+ typename std::enable_if<details::is_valid_key_value_apply_function<
94+ ApplyFunction, KeyType, ValueType>::value &&
95+ !std::is_same<void , ApplyType>::value,
96+ int >::type = 0 >
97+ inline Grouped<KeyType, ApplyType>
98+ async_apply (const Map<KeyType, ValueType> &map, ApplyFunction &&f) {
99+
100+ std::map<KeyType, std::future<ApplyType>> futures;
101+ for (const auto &pair : map) {
102+ futures[pair.first ] = async_safe (f, pair.first , pair.second );
103+ }
104+
105+ Grouped<KeyType, ApplyType> output;
106+ for (auto &pair : futures) {
107+ output.emplace (pair.first , pair.second .get ());
108+ }
109+ return output;
110+ }
111+
112+ template <template <typename ...> class Map , typename KeyType,
113+ typename ValueType, typename ApplyFunction,
114+ typename ApplyType = typename details::value_only_apply_result<
115+ ApplyFunction, ValueType>::type,
116+ typename std::enable_if<details::is_valid_value_only_apply_function<
117+ ApplyFunction, ValueType>::value &&
118+ !std::is_same<void , ApplyType>::value,
119+ int >::type = 0 >
120+ inline Grouped<KeyType, ApplyType>
121+ async_apply (const Map<KeyType, ValueType> &map, ApplyFunction &&f) {
122+
123+ std::map<KeyType, std::future<ApplyType>> futures;
124+ for (const auto &pair : map) {
125+ futures[pair.first ] = async_safe (f, pair.second );
126+ }
127+
128+ Grouped<KeyType, ApplyType> output;
129+ for (auto &pair : futures) {
130+ output.emplace (pair.first , pair.second .get ());
131+ }
132+ return output;
133+ }
134+
135+ template <template <typename ...> class Map , typename KeyType,
136+ typename ValueType, typename ApplyFunction,
137+ typename ApplyType = typename details::value_only_apply_result<
138+ ApplyFunction, ValueType>::type,
139+ typename std::enable_if<details::is_valid_value_only_apply_function<
140+ ApplyFunction, ValueType>::value &&
141+ std::is_same<void , ApplyType>::value,
142+ int >::type = 0 >
143+ inline void async_apply (const Map<KeyType, ValueType> &map, ApplyFunction &&f) {
144+ std::vector<std::future<void >> futures;
145+ for (const auto &pair : map) {
146+ futures.emplace_back (async_safe (f, pair.second ));
147+ }
148+ for (auto &f : futures) {
149+ f.get ();
150+ }
151+ }
152+
65153} // namespace albatross
66154
67155#endif /* INCLUDE_ALBATROSS_SRC_UTILS_ASYNC_UTILS_HPP_ */
0 commit comments