diff --git a/include/const_list.h b/include/const_list.h index e0c8819..ba14898 100644 --- a/include/const_list.h +++ b/include/const_list.h @@ -105,11 +105,8 @@ namespace cc { constexpr const_list& operator=(const const_list&) = delete; constexpr const_list& operator=(const_list&& other) noexcept; constexpr const_list& operator=(std::initializer_list> init) noexcept; - - constexpr void assign(size_type count, const value_type& value) noexcept; - template - constexpr void assign(InputIt first, InputIt last); - constexpr void assign(std::initializer_list values); + + constexpr void assign(std::initializer_list> 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; friend class _const_list_iterator_base; @@ -320,10 +318,33 @@ namespace cc { template constexpr const_list &const_list::operator=(std::initializer_list> init) noexcept { - *this = const_list(init); + assign(init); return *this; } + template + constexpr void const_list::assign(std::initializer_list> 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 + void const_list::clear() noexcept + { + for (auto node : *this) { + node._remove(); + } + } + template constexpr const_list_node::~const_list_node() @@ -340,10 +361,14 @@ namespace cc { } template - void const_list_node::notify_delete() + void const_list_node::_remove() { if (_delete_cb) (*_delete_cb)(); + + _prev = nullptr; + _next = nullptr; + _owner = nullptr; } } // cc