Skip to content

Commit

Permalink
Added erase overload for const_iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
Flast committed Sep 15, 2024
1 parent 1af78d4 commit acd4685
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/flat_map.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ Equivalent to `insert(hint, value_type(key, std::forward<Args>(args)...))` in th
```cpp
iterator erase(iterator pos);
iterator erase(const_iterator pos);
iterator erase(const_iterator first, const_iterator last);
size_type erase(key_type const& key)
Expand Down
2 changes: 2 additions & 0 deletions docs/flat_multimap.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ Equivalent to `insert(hint, value_type(std::forward<Args>(args)...))`.
```cpp
iterator erase(iterator pos);
iterator erase(const_iterator pos);
iterator erase(const_iterator first, const_iterator last);
size_type erase(key_type const& key)
Expand Down
2 changes: 2 additions & 0 deletions docs/flat_multiset.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ Equivalent to `insert(hint, value_type(std::forward<Args>(args)...))`.
```cpp
iterator erase(iterator pos);
iterator erase(const_iterator pos);
iterator erase(const_iterator first, const_iterator last);
size_type erase(key_type const& key)
Expand Down
2 changes: 2 additions & 0 deletions docs/flat_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ Equivalent to `insert(hint, value_type(std::forward<Args>(args)...))`.
```cpp
iterator erase(iterator pos);
iterator erase(const_iterator pos);
iterator erase(const_iterator first, const_iterator last);
size_type erase(key_type const& key)
Expand Down
1 change: 1 addition & 0 deletions flat_map/__binary_flat_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ class _binary_flat_tree_base : private detail::comparator_store<Compare>
iterator emplace_hint(const_iterator hint, Args&&... args) { return _insert(hint, value_type(std::forward<Args>(args)...)); }

iterator erase(iterator pos) { return _container.erase(pos); }
iterator erase(const_iterator pos) { return _container.erase(pos); }
iterator erase(const_iterator first, const_iterator last) { return _container.erase(first, last); }

size_type erase(key_type const& key)
Expand Down
58 changes: 58 additions & 0 deletions test/test_case/basic.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,64 @@ TEST_CASE("insertion", "[insertion]")

TEST_CASE("erase", "[erase]")
{
SECTION("erase by iterator")
{
FLAT_CONTAINER<int, int> fm =
{
MAKE_PAIR(0, 1),
MAKE_PAIR(2, 3),
MAKE_PAIR(2, 8),
MAKE_PAIR(4, 5),
MAKE_PAIR(6, 7),
};

#if MULTI_CONTAINER
REQUIRE(fm.erase(std::next(fm.begin())) != fm.end());
REQUIRE(fm.size() == 4);
#else
REQUIRE(fm.erase(std::next(fm.begin())) != fm.end());
REQUIRE(fm.size() == 3);
#endif

auto itr = fm.begin();
REQUIRE(*itr++ == MAKE_PAIR(0, 1));
#if MULTI_CONTAINER
REQUIRE(*itr++ == MAKE_PAIR(2, 8));
#endif
REQUIRE(*itr++ == MAKE_PAIR(4, 5));
REQUIRE(*itr++ == MAKE_PAIR(6, 7));
REQUIRE(itr == fm.end());
}

SECTION("erase by const_iterator")
{
FLAT_CONTAINER<int, int> fm =
{
MAKE_PAIR(0, 1),
MAKE_PAIR(2, 3),
MAKE_PAIR(2, 8),
MAKE_PAIR(4, 5),
MAKE_PAIR(6, 7),
};

#if MULTI_CONTAINER
REQUIRE(fm.erase(std::next(fm.begin())) != fm.end());
REQUIRE(fm.size() == 4);
#else
REQUIRE(fm.erase(std::next(fm.begin())) != fm.end());
REQUIRE(fm.size() == 3);
#endif

auto itr = fm.begin();
REQUIRE(*itr++ == MAKE_PAIR(0, 1));
#if MULTI_CONTAINER
REQUIRE(*itr++ == MAKE_PAIR(2, 8));
#endif
REQUIRE(*itr++ == MAKE_PAIR(4, 5));
REQUIRE(*itr++ == MAKE_PAIR(6, 7));
REQUIRE(itr == fm.end());
}

SECTION("erase by key")
{
FLAT_CONTAINER<int, int> fm =
Expand Down

0 comments on commit acd4685

Please sign in to comment.