mirror of
https://github.com/greg7mdp/parallel-hashmap.git
synced 2026-08-29 08:34:39 +08:00
Merge pull request #160 from kc9jud/master
execution: Overloads of `for_each` and `for_each_m` taking ExecutionPolicy
This commit is contained in:
Vendored
+28
-1
@@ -3318,14 +3318,41 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
template <class ExecutionPolicy, class F>
|
||||
void for_each(ExecutionPolicy&& policy, F&& fCallback) const {
|
||||
std::for_each(
|
||||
std::forward<ExecutionPolicy>(policy), sets_.begin(), sets_.end(),
|
||||
[&](auto const& inner) {
|
||||
typename Lockable::SharedLock m(const_cast<Inner&>(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<void (value_type&)> && fCallback) {
|
||||
template <class F>
|
||||
void for_each_m(F&& fCallback) {
|
||||
for (auto& inner : sets_) {
|
||||
typename Lockable::UniqueLock m(const_cast<Inner&>(inner));
|
||||
std::for_each(inner.set_.begin(), inner.set_.end(), fCallback);
|
||||
}
|
||||
}
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
template <class ExecutionPolicy, class F>
|
||||
void for_each_m(ExecutionPolicy&& policy, F&& fCallback) {
|
||||
std::for_each(
|
||||
std::forward<ExecutionPolicy>(policy), sets_.begin(), sets_.end(),
|
||||
[&](auto& inner) {
|
||||
typename Lockable::UniqueLock m(const_cast<Inner&>(inner));
|
||||
std::for_each(inner.set_.begin(), inner.set_.end(), fCallback);
|
||||
}
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Extension API: support for heterogeneous keys.
|
||||
//
|
||||
// std::unordered_set<std::string> s;
|
||||
|
||||
Reference in New Issue
Block a user