Skip to content

Commit

Permalink
use ADL lookup for erase_if instead of adding to std (issue #11)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg7mdp committed Jun 25, 2022
1 parent 9c30235 commit eab9cec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
5 changes: 1 addition & 4 deletions include/gtl/phmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5528,9 +5528,6 @@ namespace gtl {
return old_size - c.size();
}
} // priv
} // phmap

namespace std {

// ======== erase_if for gtl set containers ==================================
template <class T, class Hash, class Eq, class Alloc, class Pred>
Expand Down Expand Up @@ -5574,7 +5571,7 @@ namespace std {
return gtl::priv::erase_if(c, std::move(pred));
}

} // std
} // gtl


#ifdef _MSC_VER
Expand Down
12 changes: 6 additions & 6 deletions tests/phmap/erase_if_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace {

TEST(EraseIf, FlatHashSet_uint32) {
gtl::flat_hash_set<uint32_t> st1 = { 3, 6, 7, 9 };
auto num_erased = std::erase_if(st1, [](const uint32_t& v) { return v >= 7; });
auto num_erased = erase_if(st1, [](const uint32_t& v) { return v >= 7; });
EXPECT_TRUE(num_erased == 2);

gtl::flat_hash_set<uint32_t> st2 = { 0, 2, 3, 6 };
num_erased = std::erase_if(st2, [](const uint32_t& v) { return v <= 2; });
num_erased = erase_if(st2, [](const uint32_t& v) { return v <= 2; });
EXPECT_TRUE(num_erased == 2);

EXPECT_TRUE(st1 == st2);
Expand All @@ -23,11 +23,11 @@ TEST(EraseIf, FlatHashSet_uint32) {
TEST(EraseIf, FlatHashMap_uint64_uint32) {
using map = gtl::flat_hash_map<uint32_t, uint32_t>;
map st1 = { {3, 0}, {6, 0}, {7, 0}, {9, 0} };
auto num_erased = std::erase_if(st1, [](const map::value_type& v) { return v.first >= 7; });
auto num_erased = erase_if(st1, [](const map::value_type& v) { return v.first >= 7; });
EXPECT_TRUE(num_erased == 2);

map st2 = { {0, 0}, {2, 0}, {3, 0}, {6, 0} };
num_erased = std::erase_if(st2, [](const map::value_type& v) { return v.first <= 2; });
num_erased = erase_if(st2, [](const map::value_type& v) { return v.first <= 2; });
EXPECT_TRUE(num_erased == 2);

EXPECT_TRUE(st1 == st2);
Expand All @@ -36,11 +36,11 @@ TEST(EraseIf, FlatHashMap_uint64_uint32) {
TEST(EraseIf, ParallelFlatHashMap_uint64_uint32) {
using map = gtl::parallel_flat_hash_map<uint32_t, uint32_t>;
map st1 = { {3, 0}, {6, 0}, {7, 0}, {9, 0} };
auto num_erased = std::erase_if(st1, [](const map::value_type& v) { return v.first >= 7; });
auto num_erased = erase_if(st1, [](const map::value_type& v) { return v.first >= 7; });
EXPECT_TRUE(num_erased == 2);

map st2 = { {0, 0}, {2, 0}, {3, 0}, {6, 0} };
num_erased = std::erase_if(st2, [](const map::value_type& v) { return v.first <= 2; });
num_erased = erase_if(st2, [](const map::value_type& v) { return v.first <= 2; });
EXPECT_TRUE(num_erased == 2);

EXPECT_TRUE(st1 == st2);
Expand Down

0 comments on commit eab9cec

Please sign in to comment.