started implementing const_list as static list
This commit is contained in:
parent
57ece61c43
commit
2115cc39be
|
|
@ -69,45 +69,41 @@ namespace cc {
|
||||||
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 override { auto tmp = *this; _Base::_curr == _Base::_curr->_prev; return tmp; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename node>
|
template<typename Node>
|
||||||
requires std::derived_from<node, const_list_node<node>>
|
requires std::derived_from<Node, const_list_node<Node>>
|
||||||
class const_list {
|
class const_list {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using value_type = node;
|
using value_type = Node;
|
||||||
using size_type = std::size_t;
|
using size_type = std::size_t;
|
||||||
using difference_type = std::ptrdiff_t;
|
using difference_type = std::ptrdiff_t;
|
||||||
using reference = value_type&;
|
using reference = value_type&;
|
||||||
using const_reference = const value_type&;
|
using const_reference = const value_type&;
|
||||||
using pointer = value_type *;
|
using pointer = value_type *;
|
||||||
using const_pointer = const value_type *;
|
using const_pointer = const value_type *;
|
||||||
using iterator = _const_list_iterator<node>;
|
using iterator = _const_list_iterator<Node>;
|
||||||
using const_iterator = _const_const_list_iterator<node>;
|
using const_iterator = _const_const_list_iterator<Node>;
|
||||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
node *_start = nullptr;
|
Node *_start = nullptr;
|
||||||
node *_end = nullptr;
|
Node *_end = nullptr;
|
||||||
std::size_t _size = 0;
|
std::size_t _size = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
constexpr const_list() noexcept = default;
|
constexpr const_list() noexcept = default;
|
||||||
constexpr explicit const_list(size_type count) noexcept;
|
constexpr const_list(const const_list&) = delete;
|
||||||
constexpr const_list(size_type count, const value_type& value) noexcept;
|
|
||||||
template<std::input_iterator InputIt>
|
|
||||||
constexpr const_list(InputIt first, InputIt last);
|
|
||||||
constexpr const_list(const const_list& other) noexcept;
|
|
||||||
constexpr const_list(const_list&& other) noexcept;
|
constexpr const_list(const_list&& other) noexcept;
|
||||||
constexpr const_list(std::initializer_list<value_type> init) noexcept;
|
constexpr const_list(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept;
|
||||||
|
|
||||||
constexpr ~const_list();
|
constexpr ~const_list();
|
||||||
|
|
||||||
constexpr const_list& operator=(const const_list& other);
|
constexpr const_list& operator=(const const_list& other);
|
||||||
constexpr const_list& operator=(const_list&& other);
|
constexpr const_list& operator=(const_list&& other);
|
||||||
constexpr const_list& operator=(std::initializer_list<node> init);
|
constexpr const_list& operator=(std::initializer_list<Node> init);
|
||||||
|
|
||||||
constexpr void assign(size_type count, const value_type& value) noexcept;
|
constexpr void assign(size_type count, const value_type& value) noexcept;
|
||||||
template<std::input_iterator InputIt>
|
template<std::input_iterator InputIt>
|
||||||
|
|
@ -213,16 +209,12 @@ namespace cc {
|
||||||
const_list_node *_next = nullptr;
|
const_list_node *_next = nullptr;
|
||||||
const_list<D> *_owner = nullptr;
|
const_list<D> *_owner = nullptr;
|
||||||
|
|
||||||
virtual ~const_list_node();
|
virtual constexpr ~const_list_node();
|
||||||
|
|
||||||
friend class const_list<const_list_node>;
|
friend class const_list<const_list_node>;
|
||||||
friend class _const_list_iterator_base<const_list_node>;
|
friend class _const_list_iterator_base<const_list_node>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<std::input_iterator InputIt>
|
|
||||||
const_list(InputIt, InputIt) -> const_list<typename std::iterator_traits<InputIt>::value_type>;
|
|
||||||
|
|
||||||
template<typename N1, typename N2>
|
template<typename N1, typename N2>
|
||||||
constexpr bool operator==(const const_list<N1>& lhs,
|
constexpr bool operator==(const const_list<N1>& lhs,
|
||||||
const const_list<N2>& rhs)
|
const const_list<N2>& rhs)
|
||||||
|
|
@ -256,9 +248,48 @@ namespace cc {
|
||||||
c.remove_if(pred);
|
c.remove_if(pred);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Node>
|
||||||
|
requires std::derived_from<Node, const_list_node<Node>>
|
||||||
|
constexpr const_list<Node>::const_list(const_list &&other) noexcept
|
||||||
|
: _start(other._start), _end(other._end), _size(other._size)
|
||||||
|
{
|
||||||
|
for (auto node : other) {
|
||||||
|
node._owner = this;
|
||||||
|
}
|
||||||
|
other._size = 0;
|
||||||
|
other._start = nullptr;
|
||||||
|
other._end = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Node>
|
||||||
|
requires std::derived_from<Node, const_list_node<Node>>
|
||||||
|
constexpr const_list<Node>::const_list(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept
|
||||||
|
: _start(std::addressof(*init.begin())),
|
||||||
|
_end(std::addressof(*(--init.begin()))),
|
||||||
|
_size(init.size())
|
||||||
|
{
|
||||||
|
auto prev = init.begin();
|
||||||
|
prev->get()._owner = this;
|
||||||
|
for (auto it = ++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>
|
||||||
|
requires std::derived_from<Node, const_list_node<Node>>
|
||||||
|
constexpr const_list<Node>::~const_list()
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename D>
|
template<typename D>
|
||||||
const_list_node<D>::~const_list_node() {
|
constexpr const_list_node<D>::~const_list_node()
|
||||||
|
{
|
||||||
_owner->remove(*this);
|
_owner->remove(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue