implemented assign and clear of const_list, and added _remove for const_list_node

This commit is contained in:
cyborg1811m 2024-01-28 08:07:43 +01:00
parent 5145c5894c
commit c6e1c93b67
1 changed files with 33 additions and 8 deletions

View File

@ -106,10 +106,7 @@ namespace cc {
constexpr const_list& operator=(const_list&& other) noexcept;
constexpr const_list& operator=(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept;
constexpr void assign(size_type count, const value_type& value) noexcept;
template<std::input_iterator InputIt>
constexpr void assign(InputIt first, InputIt last);
constexpr void assign(std::initializer_list<value_type> values);
constexpr void assign(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept;
[[nodiscard]] constexpr reference front() noexcept{ return *_start; }
[[nodiscard]] constexpr const_reference front() const noexcept { return *_start; }
@ -220,10 +217,11 @@ namespace cc {
constexpr const_list_node() noexcept { asserts(); }
virtual constexpr ~const_list_node();
protected:
constexpr void on_delete(void (*cb)());
private:
void notify_delete();
void _remove();
friend class const_list<D>;
friend class _const_list_iterator_base<D>;
@ -320,10 +318,33 @@ namespace cc {
template<typename Node>
constexpr const_list<Node> &const_list<Node>::operator=(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept
{
*this = const_list(init);
assign(init);
return *this;
}
template<typename Node>
constexpr void const_list<Node>::assign(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept
{
auto prev = init.begin();
prev->get()._owner = this;
for (auto it = std::next(init.begin()); it != init.end(); ++it) {
prev->get()._next = std::addressof(it->get());
it->get()._prev = std::addressof(prev->get());
it->get()._owner = this;
prev = it;
}
}
template<typename Node>
void const_list<Node>::clear() noexcept
{
for (auto node : *this) {
node._remove();
}
}
template<typename D>
constexpr const_list_node<D>::~const_list_node()
@ -340,10 +361,14 @@ namespace cc {
}
template<typename D>
void const_list_node<D>::notify_delete()
void const_list_node<D>::_remove()
{
if (_delete_cb)
(*_delete_cb)();
_prev = nullptr;
_next = nullptr;
_owner = nullptr;
}
} // cc