diff --git a/include/const_list.h b/include/const_list.h index a301b6b..219ac72 100644 --- a/include/const_list.h +++ b/include/const_list.h @@ -84,7 +84,7 @@ namespace cc { using const_reverse_iterator = std::reverse_iterator; private: - const_list_node _tail; + const_list_node _tail { this }; std::size_t _size = 0; @@ -202,6 +202,8 @@ namespace cc { constexpr void on_delete(void (*cb)()) noexcept; private: + constexpr explicit const_list_node(const_list *owner) : _owner(owner) { asserts(); }; + constexpr void push_before(const_list_node *node) noexcept; constexpr void unlink() noexcept; @@ -332,7 +334,6 @@ namespace cc { for (auto& value : values) { // it's operator-> may fail as it could be the tail node it._node->push_before(std::addressof(value.get())); - value.get()._owner = this; } _size += values.size(); @@ -437,7 +438,6 @@ namespace cc { if (comp(*first2, *first1)) { auto next = std::next(first2); - first2._node->_owner = this; first1._node->push_before(first2._node); first2 = next; @@ -449,7 +449,6 @@ namespace cc { while (first2 != last2) { auto next = std::next(first2); - first2._node->_owner = this; _tail.push_before(first2._node); first2 = next; @@ -475,7 +474,6 @@ namespace cc { if (comp(*first2, *first1)) { auto next = std::next(first2); - first2._node->_owner = this; first1._node->push_before(first2._node); first2 = next; @@ -487,7 +485,6 @@ namespace cc { while (first2 != last2) { auto next = std::next(first2); - first2._node->_owner = this; _tail.push_before(first2._node); first2 = next; @@ -577,6 +574,8 @@ namespace cc { _prev->_next = node; _prev = node; + + node->_owner = _owner; } } // cc