Renamed the thread-safe "contains" to if_contains.

Add tests to parallel_flat_hash_map_mutex_test
This commit is contained in:
Brian McKinnon
2020-05-02 20:45:46 -05:00
parent 131a84f6ed
commit bf7203b3c8
5 changed files with 11 additions and 14 deletions
+6 -9
View File
@@ -3393,15 +3393,11 @@ public:
return Policy::value(&*it);
}
template <class K = key_type>
bool contains(const key_arg<K>& key) const {
return Base::contains(key);
}
template <class K = key_type, class V = mapped_type>
bool contains(const key_arg<K>& key, V& v) const {
std::enable_if_t<std::is_assignable<mapped_type&, V>::value,
bool> if_contains(const key_arg<K>& key, V& v) const {
typename Lockable::SharedLock m;
auto it = const_cast<parallel_hash_map *>(this)->find(key, Base::hash(key), m);
auto it = const_cast<parallel_hash_map *>(this)->find(key, this->hash(key), m);
if (it == this->end())
return false;
v = Policy::value(&*it);
@@ -3409,9 +3405,10 @@ public:
}
template <class K = key_type, class F>
bool if_contains(const key_arg<K>& key, F&& f) const {
std::enable_if_t<!std::is_assignable<mapped_type&, F>::value && std::is_invocable<F, mapped_type&>::value,
bool> if_contains(const key_arg<K>& key, F&& f) const {
typename Lockable::SharedLock m;
auto it = const_cast<parallel_hash_map*>(this)->find(key, Base::hash(key), m);
auto it = const_cast<parallel_hash_map*>(this)->find(key, this->hash(key), m);
if (it == this->end())
return false;
std::forward<F>(f)(Policy::value(&*it));