Compare commits

...

3 Commits

1 changed files with 110 additions and 393 deletions

View File

@ -8,21 +8,19 @@
#include <concepts>
#include <initializer_list>
#include <iterator>
#include "allocator.h"
#include "CompileOptional.h"
namespace cc {
template<typename D>
class const_list_node;
template<typename N>
requires std::derived_from<N, const_list_node>
class _const_list_iterator_base {
protected:
N *_curr;
N *_curr = nullptr;
public:
constexpr _const_list_iterator_base() noexcept : _curr() {}
constexpr _const_list_iterator_base() noexcept = default;
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) {}
@ -31,8 +29,8 @@ namespace cc {
constexpr virtual _const_list_iterator_base &operator++() noexcept = 0;
constexpr virtual _const_list_iterator_base &operator--() noexcept = 0;
constexpr virtual _const_list_iterator_base operator++(int) & noexcept = 0;
constexpr virtual _const_list_iterator_base operator--(int) & noexcept = 0;
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; }
};
@ -68,49 +66,44 @@ namespace cc {
constexpr _const_const_list_iterator operator--(int) & noexcept override { auto tmp = *this; _Base::_curr == _Base::_curr->_prev; return tmp; }
};
template<typename N, typename Alloc = statically_allocated>
requires std::derived_from<N, const_list_node>
template<typename Node>
class const_list {
private:
static consteval void asserts() {
static_assert(std::is_base_of_v<const_list_node<Node>, Node>, "Can only create const_list with elements derived from const_list_node");
}
public:
using value_type = N;
using value_type = Node;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
using reference = value_type&;
using const_reference = const value_type&;
using pointer = value_type *;
using const_pointer = const value_type *;
using iterator = _const_list_iterator<N>;
using const_iterator = _const_const_list_iterator<N>;
using iterator = _const_list_iterator<Node>;
using const_iterator = _const_const_list_iterator<Node>;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
private:
const_list_node *_start;
const_list_node *_end;
std::size_t _size;
CompileOptional<Alloc, std::is_same_v<Alloc, statically_allocated>> _alloc;
using alloc_defined = decltype(_alloc)::defined;
Node *_start = nullptr;
Node *_end = nullptr;
std::size_t _size = 0;
public:
constexpr const_list() noexcept = default;
constexpr explicit const_list(size_type count) noexcept;
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() noexcept { asserts(); };
constexpr const_list(const const_list&) = delete;
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& operator=(const const_list& other);
constexpr const_list& operator=(const_list&& other);
constexpr const_list& operator=(std::initializer_list<N> init);
constexpr const_list& operator=(const const_list&) = delete;
constexpr const_list& operator=(const_list&& other) noexcept;
constexpr const_list& operator=(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept;
constexpr void assign(size_type count, const value_type& value) noexcept;
template<std::input_iterator InputIt>
@ -208,403 +201,127 @@ namespace cc {
};
template<typename D>
class const_list_node {
private:
const_list_node *_prev;
const_list_node *_next;
static consteval void asserts() {
static_assert(std::is_base_of_v<const_list_node<D>, D>, "Template parameter has to be a subclass of const_list_node<*self*>");
}
friend class const_list<const_list_node>;
friend class _const_list_iterator_base<const_list_node>;
private:
const_list_node *_prev = nullptr;
const_list_node *_next = nullptr;
const_list<D> *_owner = nullptr;
public:
constexpr const_list_node() noexcept { asserts(); }
virtual constexpr ~const_list_node();
friend class const_list<D>;
friend class _const_list_iterator_base<D>;
};
template<std::input_iterator InputIt>
const_list(InputIt, InputIt) -> const_list<typename std::iterator_traits<InputIt>::value_type>;
template<typename N1, typename N2, typename Alloc1, typename Alloc2>
constexpr bool operator==(const const_list<N1, Alloc1>& lhs,
const const_list<N2, Alloc2>& rhs)
template<typename N1, typename N2>
constexpr bool operator==(const const_list<N1>& lhs,
const const_list<N2>& rhs)
{
return lhs.size() == rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
}
template<typename N1, typename N2, typename Alloc1, typename Alloc2>
constexpr auto operator<=>(const const_list<N1, Alloc1>& lhs,
const const_list<N2, Alloc2>& rhs)
template<typename N1, typename N2>
constexpr auto operator<=>(const const_list<N1>& lhs,
const const_list<N2>& rhs)
{
return std::lexicographical_compare_three_way(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
}
template<typename N, typename Alloc>
constexpr void swap(const const_list<N, Alloc>& lhs,
const const_list<N, Alloc>& rhs)
template<typename N>
constexpr void swap(const const_list<N>& lhs,
const const_list<N>& rhs)
{
lhs.swap(rhs);
}
template<typename N, typename Alloc>
constexpr const_list<N, Alloc>::size_type erase(const_list<N, Alloc>& c, const N& value)
template<typename N>
constexpr const_list<N>::size_type erase(const_list<N>& c, const N& value)
{
c.remove(value);
}
template<typename N, typename Alloc, typename Pred>
constexpr const_list<N, Alloc>::size_type erase(const_list<N, Alloc>& c, Pred pred)
template<typename N, typename Pred>
constexpr const_list<N>::size_type erase(const_list<N>& c, Pred pred)
{
c.remove_if(pred);
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr
const_list<N, Alloc>::const_list(const_list::size_type count) noexcept
template<typename Node>
constexpr const_list<Node>::const_list(const_list &&other) noexcept
: _start(other._start), _end(other._end), _size(other._size)
{
asserts();
for (auto node : other) {
node._owner = this;
}
other._size = 0;
other._start = nullptr;
other._end = nullptr;
}
template<typename Node>
constexpr const_list<Node>::const_list(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept
: _start(std::addressof(init.begin()->get())),
_end(std::addressof(std::prev(init.end())->get())),
_size(init.size())
{
asserts();
auto prev = init.begin();
prev->get()._owner = this;
for (auto it = std::next(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>
constexpr const_list<Node>::~const_list()
{
clear();
}
template<typename Node>
constexpr const_list<Node> &const_list<Node>::operator=(const_list &&other) noexcept
{
for (auto node : other) {
node._owner = this;
}
other._size = 0;
other._start = nullptr;
other._end = nullptr;
return *this;
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr
const_list<N, Alloc>::const_list(const_list::size_type count, const value_type &value) noexcept
template<typename Node>
constexpr const_list<Node> &const_list<Node>::operator=(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept
{
*this = const_list(init);
return *this;
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>
template<std::input_iterator InputIt>
constexpr const_list<N, Alloc>::const_list(InputIt first, InputIt last)
template<typename D>
constexpr const_list_node<D>::~const_list_node()
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr
const_list<N, Alloc>::const_list(const const_list &other) noexcept
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr
const_list<N, Alloc>::const_list(const_list &&other) noexcept
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr
const_list<N, Alloc>::const_list(std::initializer_list<value_type> init) noexcept
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr const_list<N, Alloc>::~const_list()
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr const_list &
const_list<N, Alloc>::operator=(const const_list &other)
{
return <#initializer#>;
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr const_list &
const_list<N, Alloc>::operator=(const_list &&other)
{
return <#initializer#>;
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr const_list &
const_list<N, Alloc>::operator=(std::initializer_list<N> init)
{
return <#initializer#>;
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void
const_list<N, Alloc>::assign(const_list::size_type count, const value_type &value) noexcept
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>
template<std::input_iterator InputIt>
constexpr void const_list<N, Alloc>::assign(InputIt first, InputIt last)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void
const_list<N, Alloc>::assign(std::initializer_list<value_type> values)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>void const_list<N, Alloc>::clear() noexcept
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr const_list::iterator
const_list<N, Alloc>::insert(const_list::const_iterator pos, const value_type &value)
{
return cc::const_list::iterator();
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr const_list::iterator
const_list<N, Alloc>::insert(const_list::const_iterator pos, value_type &&value)
{
return cc::const_list::iterator();
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr const_list::iterator
const_list<N, Alloc>::insert(const_list::const_iterator pos, const_list::size_type count, const value_type &value)
{
return cc::const_list::iterator();
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>
template<std::input_iterator InputIt>
constexpr const_list::iterator
const_list<N, Alloc>::insert(const_list::const_iterator pos, InputIt first, InputIt last)
{
return cc::const_list::iterator();
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr const_list::iterator
const_list<N, Alloc>::insert(const_list::const_iterator pos, std::initializer_list<value_type> values)
{
return cc::const_list::iterator();
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>
template<typename... Args>
constexpr const_list::iterator const_list<N, Alloc>::emplace(const_list::const_iterator pos, Args &&... args)
{
return cc::const_list::iterator();
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr const_list::iterator
const_list<N, Alloc>::erase(const_list::const_iterator pos)
{
return cc::const_list::iterator();
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr const_list::iterator
const_list<N, Alloc>::erase(const_list::const_iterator first, const_list::const_iterator last)
{
return cc::const_list::iterator();
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void
const_list<N, Alloc>::push_back(const value_type &value)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void const_list<N, Alloc>::push_back(value_type &&value)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>
template<typename... Args>
constexpr reference const_list<N, Alloc>::emplace_back(Args &&... args)
{
return <#initializer#>;
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void const_list<N, Alloc>::pop_back()
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void
const_list<N, Alloc>::push_front(const value_type &value)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void const_list<N, Alloc>::push_front(value_type &&value)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>
template<typename... Args>
constexpr reference const_list<N, Alloc>::emplace_front(Args &&... args)
{
return <#initializer#>;
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void const_list<N, Alloc>::pop_front()
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void
const_list<N, Alloc>::resize(const_list::size_type count)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void
const_list<N, Alloc>::resize(const_list::size_type count, const value_type &value)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void const_list<N, Alloc>::swap(const_list &other) noexcept
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void const_list<N, Alloc>::merge(const_list &other)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void const_list<N, Alloc>::merge(const_list &&other)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>
template<typename Compare>
constexpr void const_list<N, Alloc>::merge(const_list &other, Compare comp)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>
template<typename Compare>
constexpr void const_list<N, Alloc>::merge(const_list &&other, Compare comp)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void
const_list<N, Alloc>::splice(const_list::const_iterator pos, const_list &other)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void
const_list<N, Alloc>::splice(const_list::const_iterator pos, const_list &&other)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void
const_list<N, Alloc>::splice(const_list::const_iterator pos, const_list &other, const_list::const_iterator it)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void
const_list<N, Alloc>::splice(const_list::const_iterator pos, const_list &&other, const_list::const_iterator it)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void
const_list<N, Alloc>::splice(const_list::const_iterator pos, const_list &other, const_list::const_iterator first,
const_list::const_iterator last)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void
const_list<N, Alloc>::splice(const_list::const_iterator pos, const_list &&other, const_list::const_iterator first,
const_list::const_iterator last)
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr const_list::size_type
const_list<N, Alloc>::remove(const value_type &value)
{
return 0;
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>
template<typename UnaryPredicate>
const_list::size_type const_list<N, Alloc>::remove_if(UnaryPredicate p)
{
return 0;
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>void const_list<N, Alloc>::reverse() noexcept
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>const_list::size_type const_list<N, Alloc>::unique()
{
return 0;
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>
template<typename BinaryPredicate>
constexpr const_list::size_type const_list<N, Alloc>::unique(BinaryPredicate p)
{
return 0;
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>constexpr void const_list<N, Alloc>::sort()
{
}
template<typename N, typename Alloc>
requires std::derived_from<N, const_list_node>
template<typename Compare>
void const_list<N, Alloc>::sort(Compare comp)
{
}
_owner->remove(*this);
}
} // cc