From 09ba7d57837878a9036a47a3d6273723d0168893 Mon Sep 17 00:00:00 2001 From: cyborg1811m Date: Sun, 4 Feb 2024 23:06:45 +0100 Subject: [PATCH] added erase --- include/const_list.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/include/const_list.h b/include/const_list.h index 9d483bd..b3133d9 100644 --- a/include/const_list.h +++ b/include/const_list.h @@ -353,6 +353,40 @@ namespace cc { return it; } + template + constexpr const_list::iterator const_list::erase(const_list::const_iterator pos) + { + auto it = pos._const_cast(); + auto next = std::next(it); + + it->unlink(); + --_size; + + return next; + } + + template + constexpr const_list::iterator const_list::erase(const_list::const_iterator first, const_list::const_iterator last) + { + auto nc_last = last._const_cast(); + + if (first == last) { + return nc_last; + } + + auto next = (last == end() ? end() : std::next(nc_last)); + for (auto it = first._const_cast()._node; it != next._node; ) { + auto n = it->_next; + + it->unlink(); + --_size; + + it = n; + } + + return next; + } + template constexpr const_list_node::const_list_node(const const_list_node &other) noexcept : _delete_cb(other._delete_cb)