Added erase member function.

This commit is contained in:
Philipp Möller 2012-05-10 09:50:01 +00:00
parent 3c98b60509
commit ba92d7b9df
2 changed files with 44 additions and 8 deletions

View File

@ -216,16 +216,18 @@ public:
/// Insert \c t before \c pos in the all_view. \t will not be inserted into the skip view.
/// @returns an skip_iterator to the inserted element.
skip_iterator insert(all_iterator pos, const value_type& t)
all_iterator insert(all_iterator pos, const value_type& t)
{
return skip_.iterator_to(*all_.insert(pos.base(), *new Node(t)));
return all_.insert(pos.base(), *new Node(t));
}
// /// Insert \c t before \c pos in the all_view. \t will be inserted into the skip view.
// /// @returns an iterator to the inserted element.
// skip_iterator insert(skip_iterator pos, const value_type& t)
// {
// }
/// Insert \c t before \c pos in the all_view. \t will be inserted into the skip view.
/// @returns an iterator to the inserted element.
skip_iterator insert(skip_iterator pos, const value_type& t)
{
all_iterator it = insert(static_cast<all_iterator>(pos), t);
return skip_.insert(pos.base(), *it.base());
}
/// Insert the range [begin,end) into the all view. If the container
/// is empty() the range will also be visible in the skip view.
@ -243,6 +245,17 @@ public:
}
}
/// Drop the contents of iterator \c it from both views.
all_iterator erase(all_iterator it)
{
if(!is_skipped(it)) {
skip_.erase(skip_.iterator_to(*it.base()));
}
return all_.erase_and_dispose(it.base(), Node_disposer());
}
size_type
all_size() const { return all_.size(); }

View File

@ -58,7 +58,7 @@ BOOST_FIXTURE_TEST_CASE( test_insert, Fixture )
all.begin(), all.end());
BOOST_CHECK_EQUAL_COLLECTIONS(l.skip_begin(), l.skip_end(),
skips.begin(), skips.end());
// the same goes for inserting at an arbitrary position
skip::all_iterator pos = boost::next(l.all_begin(), 3);
l.insert(boost::next(l.all_begin(), 3)
@ -203,6 +203,29 @@ BOOST_FIXTURE_TEST_CASE( test_implicit_conversion, Fixture )
BOOST_CHECK(all == l.all_begin());
}
BOOST_FIXTURE_TEST_CASE( test_erase, Fixture )
{
// erase 3
l.erase(boost::next(l.all_begin(), 2));
skips.erase(std::remove(skips.begin(), skips.end(), 3), skips.end());
all.erase(std::remove(all.begin(), all.end(), 3), all.end());
BOOST_CHECK_EQUAL_COLLECTIONS(l.skip_begin(), l.skip_end(),
skips.begin(), skips.end());
BOOST_CHECK_EQUAL_COLLECTIONS(l.all_begin(), l.all_end(),
all.begin(), all.end());
// skip 2 first and then erase it
l.skip(boost::next(l.all_begin()));
skips.erase(std::remove(skips.begin(), skips.end(), 2), skips.end());
all.erase(std::remove(all.begin(), all.end(), 2), all.end());
l.erase(boost::next(l.all_begin()));
BOOST_CHECK_EQUAL_COLLECTIONS(l.skip_begin(), l.skip_end(),
skips.begin(), skips.end());
BOOST_CHECK_EQUAL_COLLECTIONS(l.all_begin(), l.all_end(),
all.begin(), all.end());
}
// trick cgal_create_cmake_script
// int main()
// {