implemented const_list::assign
This commit is contained in:
parent
6d9e70068c
commit
4df86f81c5
|
|
@ -25,13 +25,13 @@ namespace cc {
|
|||
|
||||
public:
|
||||
constexpr _const_list_iterator_base() noexcept = default;
|
||||
constexpr explicit _const_list_iterator_base(N *curr) noexcept : _curr(curr) {}
|
||||
constexpr explicit _const_list_iterator_base(const_list_node<N> *curr) noexcept : _curr(curr) {}
|
||||
constexpr _const_list_iterator_base(const _const_list_iterator_base& other) noexcept : _curr(other._curr) {}
|
||||
|
||||
constexpr virtual const N& operator*() const noexcept { return *dynamic_cast<N*>(_curr); }
|
||||
constexpr virtual const N* operator->() const noexcept { return dynamic_cast<N*>(_curr); }
|
||||
|
||||
constexpr virtual const_list_node<N>* node() const { return _curr; }
|
||||
constexpr const_list_node<N>* node() const { return _curr; }
|
||||
|
||||
constexpr virtual _const_list_iterator_base &operator++() noexcept { return *this; };
|
||||
constexpr virtual _const_list_iterator_base &operator--() noexcept { return *this; };
|
||||
|
|
@ -39,7 +39,6 @@ namespace cc {
|
|||
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>;
|
||||
};
|
||||
|
|
@ -49,7 +48,7 @@ namespace cc {
|
|||
using _Base = _const_list_iterator_base<N>;
|
||||
public:
|
||||
constexpr _const_list_iterator() noexcept : _Base() {}
|
||||
constexpr explicit _const_list_iterator(N *curr) noexcept : _Base(curr) {}
|
||||
constexpr explicit _const_list_iterator(const_list_node<N> *curr) noexcept : _Base(curr) {}
|
||||
constexpr _const_list_iterator(const _Base& other) noexcept : _Base(other) {}
|
||||
|
||||
constexpr N& operator*() const noexcept override { return *dynamic_cast<N*>(_Base::_curr); }
|
||||
|
|
@ -67,15 +66,20 @@ namespace cc {
|
|||
using _Base = _const_list_iterator_base<N>;
|
||||
public:
|
||||
constexpr _const_const_list_iterator() : _Base() {}
|
||||
constexpr explicit _const_const_list_iterator(N *curr) : _Base(curr) {}
|
||||
constexpr explicit _const_const_list_iterator(const const_list_node<N> *curr) : _Base(const_cast<const_list_node<N>*>(curr)) {} // @TODO: change code to remove const_cast
|
||||
constexpr _const_const_list_iterator(const _Base& other) noexcept : _Base(other) {}
|
||||
|
||||
constexpr const N* node() noexcept override { return _Base::node(); }
|
||||
constexpr const N* node() noexcept { 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->_prev; return *this; }
|
||||
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 { auto tmp = *this; _Base::_curr = _Base::_curr->_prev; return tmp; }
|
||||
|
||||
private:
|
||||
constexpr _const_list_iterator<N> _const_cast() noexcept { return _const_list_iterator<N>(_Base::_curr); }
|
||||
|
||||
friend class const_list<N>;
|
||||
};
|
||||
|
||||
template<typename Node>
|
||||
|
|
@ -142,6 +146,7 @@ namespace cc {
|
|||
[[nodiscard]] constexpr const_reverse_iterator crend() const noexcept { return std::reverse_iterator<const_iterator>(begin()); };
|
||||
|
||||
[[nodiscard]] constexpr bool empty() const noexcept { return _size == 0; }
|
||||
[[nodiscard]] constexpr size_type size() const noexcept { return _size; }
|
||||
[[nodiscard]] constexpr size_type max_size() const noexcept { return SIZE_MAX; }
|
||||
|
||||
void clear() noexcept;
|
||||
|
|
@ -149,9 +154,6 @@ namespace cc {
|
|||
constexpr iterator insert(const_iterator pos, value_type& value);
|
||||
constexpr iterator insert(const_iterator pos, std::initializer_list<std::reference_wrapper<value_type>> values);
|
||||
|
||||
template<typename ...Args>
|
||||
constexpr iterator emplace(const_iterator pos, Args&&... args);
|
||||
|
||||
constexpr iterator erase(const_iterator pos);
|
||||
constexpr iterator erase(const_iterator first, const_iterator last);
|
||||
|
||||
|
|
@ -329,11 +331,7 @@ namespace cc {
|
|||
{
|
||||
clear();
|
||||
|
||||
for (auto& value : init) {
|
||||
_tail.push_before(std::addressof(value.get()));
|
||||
value.get()._owner = this;
|
||||
}
|
||||
_size += init.size();
|
||||
insert(begin(), init);
|
||||
}
|
||||
|
||||
template<typename Node>
|
||||
|
|
@ -351,25 +349,29 @@ namespace cc {
|
|||
template<typename Node>
|
||||
constexpr const_list<Node>::iterator const_list<Node>::insert(const_iterator pos, value_type &value)
|
||||
{
|
||||
pos->push_before(value);
|
||||
auto it = pos._const_cast();
|
||||
|
||||
it->push_before(value);
|
||||
++_size;
|
||||
|
||||
return --pos;
|
||||
return --it;
|
||||
}
|
||||
|
||||
template<typename Node>
|
||||
constexpr const_list<Node>::iterator const_list<Node>::insert(const_list::const_iterator pos,
|
||||
std::initializer_list<std::reference_wrapper<value_type>> values)
|
||||
{
|
||||
auto prev = pos.node();
|
||||
for (auto& it = values.rbegin(); it != values.rend(); ++it) {
|
||||
prev->push_before(it->get());
|
||||
prev = it->get();
|
||||
auto it = pos._const_cast();
|
||||
|
||||
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();
|
||||
|
||||
return iterator(prev);
|
||||
return it;
|
||||
}
|
||||
|
||||
template<typename D>
|
||||
|
|
|
|||
Loading…
Reference in New Issue