made const_list compilable

This commit is contained in:
cyborg1811m 2024-02-04 15:15:14 +01:00
parent 9581f0028c
commit 6d9e70068c
1 changed files with 39 additions and 7 deletions

View File

@ -119,11 +119,11 @@ namespace cc {
constexpr void assign(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept; constexpr void assign(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept;
[[nodiscard]] constexpr reference front() noexcept{ return dynamic_cast<Node&>(_tail._next); } [[nodiscard]] constexpr reference front() noexcept{ return *dynamic_cast<Node*>(_tail._next); }
[[nodiscard]] constexpr const_reference front() const noexcept { return dynamic_cast<Node&>(_tail._next); } [[nodiscard]] constexpr const_reference front() const noexcept { return *dynamic_cast<Node*>(_tail._next); }
[[nodiscard]] constexpr reference back() noexcept { return dynamic_cast<Node&>(_tail._prev); } [[nodiscard]] constexpr reference back() noexcept { return *dynamic_cast<Node*>(_tail._prev); }
[[nodiscard]] constexpr const_reference back() const noexcept { return dynamic_cast<Node&>(_tail._prev); } [[nodiscard]] constexpr const_reference back() const noexcept { return *dynamic_cast<Node*>(_tail._prev); }
[[nodiscard]] constexpr iterator begin() noexcept { return iterator(_tail._next); }; [[nodiscard]] constexpr iterator begin() noexcept { return iterator(_tail._next); };
[[nodiscard]] constexpr const_iterator begin() const noexcept { return const_iterator(_tail._next); }; [[nodiscard]] constexpr const_iterator begin() const noexcept { return const_iterator(_tail._next); };
@ -226,6 +226,9 @@ namespace cc {
constexpr const_list_node(const_list_node&& other) noexcept; constexpr const_list_node(const_list_node&& other) noexcept;
virtual constexpr ~const_list_node(); virtual constexpr ~const_list_node();
constexpr const_list_node<D>& operator=(const const_list_node& other) noexcept;
constexpr const_list_node<D>& operator=(const_list_node&& other) noexcept;
protected: protected:
constexpr void on_delete(void (*cb)()) noexcept; constexpr void on_delete(void (*cb)()) noexcept;
@ -274,14 +277,15 @@ namespace cc {
template<typename Node> template<typename Node>
constexpr const_list<Node>::const_list(const_list &&other) noexcept constexpr const_list<Node>::const_list(const_list &&other) noexcept
: _tail(std::move(other._tail)), : _size(other._size)
_size(other._size)
{ {
asserts(); asserts();
for (auto node : other) { for (auto& node : other) {
node._owner = this; node._owner = this;
} }
_tail = std::move(other._tail);
} }
template<typename Node> template<typename Node>
@ -327,6 +331,7 @@ namespace cc {
for (auto& value : init) { for (auto& value : init) {
_tail.push_before(std::addressof(value.get())); _tail.push_before(std::addressof(value.get()));
value.get()._owner = this;
} }
_size += init.size(); _size += init.size();
} }
@ -380,6 +385,10 @@ namespace cc {
{ {
_prev->_next = this; _prev->_next = this;
_next->_prev = this; _next->_prev = this;
// without this the destructor of other would delete moved nodes
other._next = std::addressof(other);
other._prev = std::addressof(other);
} }
template<typename D> template<typename D>
@ -390,6 +399,29 @@ namespace cc {
unlink(); unlink();
} }
template<typename D>
constexpr const_list_node<D> &const_list_node<D>::operator=(const const_list_node &other) noexcept
{
return *this;
}
template<typename D>
constexpr const_list_node<D> &const_list_node<D>::operator=(const_list_node &&other) noexcept
{
_prev = other._prev;
_next = other._next;
_delete_cb = other._delete_cb;
_prev->_next = this;
_next->_prev = this;
// without this the destructor of other would delete moved nodes
other._next = std::addressof(other);
other._prev = std::addressof(other);
return *this;
}
template<typename D> template<typename D>
constexpr void const_list_node<D>::on_delete(void (*cb)()) noexcept constexpr void const_list_node<D>::on_delete(void (*cb)()) noexcept
{ {