continued work on tail node
This commit is contained in:
parent
398735ee3a
commit
9581f0028c
|
|
@ -15,27 +15,33 @@ namespace cc {
|
||||||
template<typename D>
|
template<typename D>
|
||||||
class const_list_node;
|
class const_list_node;
|
||||||
|
|
||||||
|
template<typename Node>
|
||||||
|
class const_list;
|
||||||
|
|
||||||
template<typename N>
|
template<typename N>
|
||||||
class _const_list_iterator_base {
|
class _const_list_iterator_base {
|
||||||
protected:
|
protected:
|
||||||
N *_curr = nullptr;
|
const_list_node<N> *_curr = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr _const_list_iterator_base() noexcept = default;
|
constexpr _const_list_iterator_base() noexcept = default;
|
||||||
constexpr explicit _const_list_iterator_base(N *curr) noexcept : _curr(curr) {}
|
constexpr explicit _const_list_iterator_base(N *curr) noexcept : _curr(curr) {}
|
||||||
constexpr _const_list_iterator_base(const _const_list_iterator_base& other) noexcept : _curr(other._curr) {}
|
constexpr _const_list_iterator_base(const _const_list_iterator_base& other) noexcept : _curr(other._curr) {}
|
||||||
|
|
||||||
constexpr virtual const N& operator*() const noexcept { return *_curr; }
|
constexpr virtual const N& operator*() const noexcept { return *dynamic_cast<N*>(_curr); }
|
||||||
constexpr virtual const N* operator->() const noexcept { return _curr; }
|
constexpr virtual const N* operator->() const noexcept { return dynamic_cast<N*>(_curr); }
|
||||||
|
|
||||||
constexpr virtual N* node() const { return _curr; }
|
constexpr virtual const_list_node<N>* node() const { return _curr; }
|
||||||
|
|
||||||
constexpr virtual _const_list_iterator_base &operator++() noexcept = 0;
|
constexpr virtual _const_list_iterator_base &operator++() noexcept { return *this; };
|
||||||
constexpr virtual _const_list_iterator_base &operator--() noexcept = 0;
|
constexpr virtual _const_list_iterator_base &operator--() noexcept { return *this; };
|
||||||
constexpr virtual _const_list_iterator_base &operator++(int) & noexcept = 0;
|
|
||||||
constexpr virtual _const_list_iterator_base &operator--(int) & noexcept = 0;
|
|
||||||
|
|
||||||
constexpr bool operator==(const _const_list_iterator_base &other) { return _curr == other._curr; }
|
constexpr bool operator==(const _const_list_iterator_base &other) const { return _curr == other._curr; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
constexpr _const_list_iterator_base(const_list_node<N> *tail) : _curr(tail) {}
|
||||||
|
|
||||||
|
friend class const_list<N>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename N>
|
template<typename N>
|
||||||
|
|
@ -46,13 +52,14 @@ namespace cc {
|
||||||
constexpr explicit _const_list_iterator(N *curr) noexcept : _Base(curr) {}
|
constexpr explicit _const_list_iterator(N *curr) noexcept : _Base(curr) {}
|
||||||
constexpr _const_list_iterator(const _Base& other) noexcept : _Base(other) {}
|
constexpr _const_list_iterator(const _Base& other) noexcept : _Base(other) {}
|
||||||
|
|
||||||
constexpr N& operator*() const override { return *_Base::_curr; }
|
constexpr N& operator*() const noexcept override { return *dynamic_cast<N*>(_Base::_curr); }
|
||||||
constexpr N* operator->() const override { return _Base::_curr; }
|
constexpr N* operator->() const noexcept override { return dynamic_cast<N*>(_Base::_curr); }
|
||||||
|
|
||||||
|
constexpr _const_list_iterator &operator++() noexcept override { _Base::_curr = _Base::_curr->_next; return *this; }
|
||||||
|
constexpr _const_list_iterator &operator--() noexcept override { _Base::_curr = _Base::_curr->_prev; return *this; }
|
||||||
|
constexpr _const_list_iterator operator++(int) noexcept { auto tmp = *this; _Base::_curr = _Base::_curr->_next; return tmp; }
|
||||||
|
constexpr _const_list_iterator operator--(int) noexcept { auto tmp = *this; _Base::_curr = _Base::_curr->_prev; return tmp; }
|
||||||
|
|
||||||
constexpr _const_list_iterator &operator++() noexcept override { _Base::_curr == _Base::_curr->_next; return *this; }
|
|
||||||
constexpr _const_list_iterator &operator--() noexcept override { _Base::_curr == _Base::_curr->_prev; return *this; }
|
|
||||||
constexpr _const_list_iterator operator++(int) & noexcept override { auto tmp = *this; _Base::_curr == _Base::_curr->_next; return tmp; }
|
|
||||||
constexpr _const_list_iterator operator--(int) & noexcept override { auto tmp = *this; _Base::_curr == _Base::_curr->_prev; return tmp; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename N>
|
template<typename N>
|
||||||
|
|
@ -65,10 +72,10 @@ namespace cc {
|
||||||
|
|
||||||
constexpr const N* node() noexcept override { return _Base::node(); }
|
constexpr const N* node() noexcept override { return _Base::node(); }
|
||||||
|
|
||||||
constexpr _const_const_list_iterator &operator++() noexcept override { _Base::_curr == _Base::_curr->_next; return *this; }
|
constexpr _const_const_list_iterator &operator++() noexcept override { _Base::_curr = _Base::_curr->_next; return *this; }
|
||||||
constexpr _const_const_list_iterator &operator--() noexcept override { _Base::_curr == _Base::_curr->_prev; return *this; }
|
constexpr _const_const_list_iterator &operator--() noexcept override { _Base::_curr = _Base::_curr->_prev; return *this; }
|
||||||
constexpr _const_const_list_iterator operator++(int) & noexcept override { auto tmp = *this; _Base::_curr == _Base::_curr->_next; return tmp; }
|
constexpr _const_const_list_iterator operator++(int) noexcept { auto tmp = *this; _Base::_curr = _Base::_curr->_next; return tmp; }
|
||||||
constexpr _const_const_list_iterator operator--(int) & noexcept override { auto tmp = *this; _Base::_curr == _Base::_curr->_prev; return tmp; }
|
constexpr _const_const_list_iterator operator--(int) noexcept { auto tmp = *this; _Base::_curr = _Base::_curr->_prev; return tmp; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Node>
|
template<typename Node>
|
||||||
|
|
@ -112,19 +119,19 @@ 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 *_start; }
|
[[nodiscard]] constexpr reference front() noexcept{ return dynamic_cast<Node&>(_tail._next); }
|
||||||
[[nodiscard]] constexpr const_reference front() const noexcept { return *_start; }
|
[[nodiscard]] constexpr const_reference front() const noexcept { return dynamic_cast<Node&>(_tail._next); }
|
||||||
|
|
||||||
[[nodiscard]] constexpr reference back() noexcept { return _end; }
|
[[nodiscard]] constexpr reference back() noexcept { return dynamic_cast<Node&>(_tail._prev); }
|
||||||
[[nodiscard]] constexpr const_reference back() const noexcept { return _end; }
|
[[nodiscard]] constexpr const_reference back() const noexcept { return dynamic_cast<Node&>(_tail._prev); }
|
||||||
|
|
||||||
[[nodiscard]] constexpr iterator begin() noexcept { return iterator(_start); };
|
[[nodiscard]] constexpr iterator begin() noexcept { return iterator(_tail._next); };
|
||||||
[[nodiscard]] constexpr const_iterator begin() const noexcept { return const_iterator(_start); };
|
[[nodiscard]] constexpr const_iterator begin() const noexcept { return const_iterator(_tail._next); };
|
||||||
[[nodiscard]] constexpr const_iterator cbegin() const noexcept { return const_iterator(_start); };
|
[[nodiscard]] constexpr const_iterator cbegin() const noexcept { return const_iterator(_tail._next); };
|
||||||
|
|
||||||
[[nodiscard]] constexpr iterator end() noexcept { return iterator(); };
|
[[nodiscard]] constexpr iterator end() noexcept { return iterator(&_tail); };
|
||||||
[[nodiscard]] constexpr const_iterator end() const noexcept { return const_iterator(); };
|
[[nodiscard]] constexpr const_iterator end() const noexcept { return const_iterator(&_tail); };
|
||||||
[[nodiscard]] constexpr const_iterator cend() const noexcept { return const_iterator(); };
|
[[nodiscard]] constexpr const_iterator cend() const noexcept { return const_iterator(&_tail); };
|
||||||
|
|
||||||
[[nodiscard]] constexpr reverse_iterator rbegin() noexcept { return std::reverse_iterator<iterator>(end()); };
|
[[nodiscard]] constexpr reverse_iterator rbegin() noexcept { return std::reverse_iterator<iterator>(end()); };
|
||||||
[[nodiscard]] constexpr const_reverse_iterator rbegin() const noexcept { return std::reverse_iterator<const_iterator>(end()); };
|
[[nodiscard]] constexpr const_reverse_iterator rbegin() const noexcept { return std::reverse_iterator<const_iterator>(end()); };
|
||||||
|
|
@ -228,6 +235,8 @@ namespace cc {
|
||||||
|
|
||||||
friend class const_list<D>;
|
friend class const_list<D>;
|
||||||
friend class _const_list_iterator_base<D>;
|
friend class _const_list_iterator_base<D>;
|
||||||
|
friend class _const_list_iterator<D>;
|
||||||
|
friend class _const_const_list_iterator<D>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename N1, typename N2>
|
template<typename N1, typename N2>
|
||||||
|
|
@ -282,11 +291,7 @@ namespace cc {
|
||||||
{
|
{
|
||||||
asserts();
|
asserts();
|
||||||
|
|
||||||
auto prev = &_tail;
|
assign(init);
|
||||||
for (auto& it = init.rbegin(); it != init.rend(); ++it) {
|
|
||||||
prev->push_before(it->get());
|
|
||||||
prev = it->get();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Node>
|
template<typename Node>
|
||||||
|
|
@ -320,16 +325,22 @@ namespace cc {
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
|
for (auto& value : init) {
|
||||||
|
_tail.push_before(std::addressof(value.get()));
|
||||||
|
}
|
||||||
|
_size += init.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Node>
|
template<typename Node>
|
||||||
void const_list<Node>::clear() noexcept
|
void const_list<Node>::clear() noexcept
|
||||||
{
|
{
|
||||||
for (auto node : *this) {
|
for (auto node = _tail._next; _tail._next != std::addressof(_tail); ) {
|
||||||
node.unlink();
|
auto next = node->_next;
|
||||||
|
node->unlink();
|
||||||
|
node = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Node>
|
template<typename Node>
|
||||||
|
|
@ -406,7 +417,7 @@ namespace cc {
|
||||||
node->_prev = _prev;
|
node->_prev = _prev;
|
||||||
node->_next = this;
|
node->_next = this;
|
||||||
|
|
||||||
_prev->next = node;
|
_prev->_next = node;
|
||||||
_prev = node;
|
_prev = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue