From 6fc51c1b49cc2470591d6612622a9f8f543c557c Mon Sep 17 00:00:00 2001 From: Patrick Fasano Date: Thu, 21 Jul 2022 12:19:58 -0400 Subject: [PATCH] execution: Overloads of for_each and for_each_m taking ExecutionPolicy * Adds additional overloads to `for_each` and `for_each_m` that accept execution policies. * Execution policy is applied to the loop over subsets. --- parallel_hashmap/phmap.h | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index 4e357c7..a6592bc 100644 --- a/parallel_hashmap/phmap.h +++ b/parallel_hashmap/phmap.h @@ -3318,14 +3318,41 @@ public: } } +#if __cplusplus >= 201703L + template + void for_each(ExecutionPolicy&& policy, F&& fCallback) const { + std::for_each( + std::forward(policy), sets_.begin(), sets_.end(), + [&](auto const& inner) { + typename Lockable::SharedLock m(const_cast(inner)); + std::for_each(inner.set_.begin(), inner.set_.end(), fCallback); + } + ); + } +#endif + // this version allows to modify the values - void for_each_m(std::function && fCallback) { + template + void for_each_m(F&& fCallback) { for (auto& inner : sets_) { typename Lockable::UniqueLock m(const_cast(inner)); std::for_each(inner.set_.begin(), inner.set_.end(), fCallback); } } +#if __cplusplus >= 201703L + template + void for_each_m(ExecutionPolicy&& policy, F&& fCallback) { + std::for_each( + std::forward(policy), sets_.begin(), sets_.end(), + [&](auto& inner) { + typename Lockable::UniqueLock m(const_cast(inner)); + std::for_each(inner.set_.begin(), inner.set_.end(), fCallback); + } + ); + } +#endif + // Extension API: support for heterogeneous keys. // // std::unordered_set s;