implemented assign and clear of const_list, and added _remove for const_list_node
This commit is contained in:
parent
5145c5894c
commit
c6e1c93b67
|
|
@ -105,11 +105,8 @@ namespace cc {
|
||||||
constexpr const_list& operator=(const const_list&) = delete;
|
constexpr const_list& operator=(const const_list&) = delete;
|
||||||
constexpr const_list& operator=(const_list&& other) noexcept;
|
constexpr const_list& operator=(const_list&& other) noexcept;
|
||||||
constexpr const_list& operator=(std::initializer_list<std::reference_wrapper<value_type>> init) 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;
|
constexpr void assign(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept;
|
||||||
template<std::input_iterator InputIt>
|
|
||||||
constexpr void assign(InputIt first, InputIt last);
|
|
||||||
constexpr void assign(std::initializer_list<value_type> values);
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr reference front() noexcept{ return *_start; }
|
[[nodiscard]] constexpr reference front() noexcept{ return *_start; }
|
||||||
[[nodiscard]] constexpr const_reference front() const noexcept { return *_start; }
|
[[nodiscard]] constexpr const_reference front() const noexcept { return *_start; }
|
||||||
|
|
@ -220,10 +217,11 @@ namespace cc {
|
||||||
constexpr const_list_node() noexcept { asserts(); }
|
constexpr const_list_node() noexcept { asserts(); }
|
||||||
virtual constexpr ~const_list_node();
|
virtual constexpr ~const_list_node();
|
||||||
|
|
||||||
|
protected:
|
||||||
constexpr void on_delete(void (*cb)());
|
constexpr void on_delete(void (*cb)());
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void notify_delete();
|
void _remove();
|
||||||
|
|
||||||
friend class const_list<D>;
|
friend class const_list<D>;
|
||||||
friend class _const_list_iterator_base<D>;
|
friend class _const_list_iterator_base<D>;
|
||||||
|
|
@ -320,10 +318,33 @@ namespace cc {
|
||||||
template<typename Node>
|
template<typename Node>
|
||||||
constexpr const_list<Node> &const_list<Node>::operator=(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept
|
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;
|
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>
|
template<typename D>
|
||||||
constexpr const_list_node<D>::~const_list_node()
|
constexpr const_list_node<D>::~const_list_node()
|
||||||
|
|
@ -340,10 +361,14 @@ namespace cc {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename D>
|
template<typename D>
|
||||||
void const_list_node<D>::notify_delete()
|
void const_list_node<D>::_remove()
|
||||||
{
|
{
|
||||||
if (_delete_cb)
|
if (_delete_cb)
|
||||||
(*_delete_cb)();
|
(*_delete_cb)();
|
||||||
|
|
||||||
|
_prev = nullptr;
|
||||||
|
_next = nullptr;
|
||||||
|
_owner = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // cc
|
} // cc
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue