Skip to content

Commit

Permalink
Add fixes from phmap repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg7mdp committed Nov 19, 2023
1 parent e2a5faa commit cef6efb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
15 changes: 9 additions & 6 deletions include/gtl/phmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3725,12 +3725,15 @@ class parallel_hash_set {
template<class K = key_type, class F, class L>
bool erase_if_impl(const key_arg<K>& key, F&& f) {
static_assert(std::is_invocable_v<F, value_type&>);
L m;
auto it = this->template find<K, L>(key, this->hash(key), m);
if (it == this->end())
return false;
if (std::forward<F>(f)(const_cast<value_type&>(*it))) {
this->erase(it);
auto hashval = this->hash(key);
Inner& inner = sets_[subidx(hashval)];
auto& set = inner.set_;
L m(inner);
auto it = set.find(key, hashval);
if (it == set.end()) return false;
if (std::forward<F>(f)(const_cast<value_type &>(*it)))
{
set._erase(it);
return true;
}
return false;
Expand Down
6 changes: 3 additions & 3 deletions tests/phmap/raw_hash_set_allocator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CheckedAlloc {
using propagate_on_container_swap = std::integral_constant<bool, (Spec & kPropagateOnSwap) != 0>;

CheckedAlloc select_on_container_copy_construction() const {
if (Spec & kPropagateOnCopy)
if constexpr (Spec & kPropagateOnCopy)
return *this;
return {};
}
Expand All @@ -86,13 +86,13 @@ class CheckedAlloc {

size_t num_allocs() const { return state_->num_allocs; }

void swap(CheckedAlloc& that) {
void swap(CheckedAlloc& that) noexcept {
using std::swap;
swap(id_, that.id_);
swap(state_, that.state_);
}

friend void swap(CheckedAlloc& a, CheckedAlloc& b) { a.swap(b); }
friend void swap(CheckedAlloc& a, CheckedAlloc& b) noexcept { a.swap(b); }

friend std::ostream& operator<<(std::ostream& o, const CheckedAlloc& a) { return o << "alloc(" << a.id_ << ")"; }

Expand Down

0 comments on commit cef6efb

Please sign in to comment.