/**
This file is a part of rexy's general purpose library
Copyright (C) 2022 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#ifndef REXY_LLIST_HPP
#define REXY_LLIST_HPP
#include //size_t, ptrdiff_t
#include "allocator.hpp" //TODO
#include "detail/hasallocator.hpp"
#include //bidirectional_iterator_tag, reverse_iterator
#include //allocator_traits
#include
#include //pair
namespace rexy{
template
class list;
namespace detail{
struct node_base{
node_base* next = nullptr;
node_base* prev = nullptr;
};
template
struct list_iterator;
template
struct const_list_iterator;
template
struct node;
}
template>
class list : protected detail::hasallocator::template rebind_alloc>>
{
private:
using node_allocator_type = detail::hasallocator::template rebind_alloc>>;
public:
using value_type = T;
using allocator_type = Alloc;
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 = detail::list_iterator;
using const_iterator = detail::const_list_iterator;
using reverse_iterator = std::reverse_iterator;
using const_reverse_iterator = std::reverse_iterator;
public:
using node = detail::node;
private:
detail::node_base m_sentinel = {&m_sentinel, &m_sentinel};
size_type m_size = 0;
public:
constexpr list(void) = default;
constexpr explicit list(const allocator_type& alloc);
REXY_CPP20_CONSTEXPR list(size_type count, const_reference value = value_type(), const allocator_type& = allocator_type());
REXY_CPP20_CONSTEXPR explicit list(size_type count, const allocator_type& alloc = allocator_type());
template
REXY_CPP20_CONSTEXPR list(InputIt first, InputIt last, const allocator_type& alloc = allocator_type());
REXY_CPP20_CONSTEXPR list(const list& other, const allocator_type& alloc = allocator_type());
REXY_CPP20_CONSTEXPR list(list&& other, const allocator_type& alloc = allocator_type());
REXY_CPP20_CONSTEXPR list(std::initializer_list l, const allocator_type& alloc = allocator_type());
REXY_CPP20_CONSTEXPR ~list(void);
REXY_CPP20_CONSTEXPR list& operator=(const list& other);
REXY_CPP20_CONSTEXPR list& operator=(list&& other);
REXY_CPP20_CONSTEXPR list& operator=(std::initializer_list l);
constexpr bool operator==(const list& other)const noexcept;
#if __cpp_impl_three_way_comparison
constexpr auto operator<=>(const list& other)const noexcept;
#else
constexpr bool operator!=(const list& other)const noexcept;
constexpr bool operator<(const list& other)const noexcept;
constexpr bool operator<=(const list& other)const noexcept;
constexpr bool operator>(const list& other)const noexcept;
constexpr bool operator>=(const list& other)const noexcept;
#endif
REXY_CPP20_CONSTEXPR void assign(size_type count, const_reference value);
template
REXY_CPP20_CONSTEXPR void assign(InputIt first, InputIt last);
REXY_CPP20_CONSTEXPR void assign(std::initializer_list l);
constexpr allocator_type get_allocator(void)const noexcept;
constexpr reference front(void);
constexpr const_reference front(void)const;
constexpr reference back(void);
constexpr const_reference back(void)const;
constexpr iterator begin(void)noexcept;
constexpr const_iterator begin(void)const noexcept;
constexpr const_iterator cbegin(void)const noexcept;
constexpr iterator end(void)noexcept;
constexpr const_iterator end(void)const noexcept;
constexpr const_iterator cend(void)const noexcept;
constexpr iterator next(iterator i)noexcept;
constexpr const_iterator next(const_iterator i)noexcept;
constexpr iterator prev(iterator i)noexcept;
constexpr const_iterator prev(const_iterator i)noexcept;
constexpr reverse_iterator rbegin(void)noexcept;
constexpr const_reverse_iterator rbegin(void)const noexcept;
constexpr const_reverse_iterator crbegin(void)const noexcept;
constexpr reverse_iterator rend(void)noexcept;
constexpr const_reverse_iterator rend(void)const noexcept;
constexpr const_reverse_iterator crend(void)const noexcept;
constexpr bool empty(void)const noexcept;
constexpr size_type size(void)const noexcept;
constexpr size_type max_size(void)const noexcept;
REXY_CPP20_CONSTEXPR void clear(void)noexcept;
REXY_CPP20_CONSTEXPR iterator insert(const_iterator pos, const_reference value);
REXY_CPP20_CONSTEXPR iterator insert(const_iterator pos, value_type&& value);
REXY_CPP20_CONSTEXPR iterator insert(const_iterator pos, size_type count, const_reference value);
template
REXY_CPP20_CONSTEXPR iterator insert(const_iterator pos, InputIt first, InputIt last);
REXY_CPP20_CONSTEXPR iterator insert(const_iterator pos, std::initializer_list l);
template
REXY_CPP20_CONSTEXPR iterator emplace(const_iterator pos, Args&&... args);
REXY_CPP20_CONSTEXPR iterator erase(const_iterator pos);
REXY_CPP20_CONSTEXPR iterator erase(const_iterator first, const_iterator last);
REXY_CPP20_CONSTEXPR reference push_back(const_reference value);
REXY_CPP20_CONSTEXPR reference push_back(value_type&& value);
template
REXY_CPP20_CONSTEXPR reference emplace_back(Args&&... args);
REXY_CPP20_CONSTEXPR void pop_back(void);
REXY_CPP20_CONSTEXPR reference push_front(const_reference value);
REXY_CPP20_CONSTEXPR reference push_front(value_type&& value);
template
REXY_CPP20_CONSTEXPR reference emplace_front(Args&&... args);
REXY_CPP20_CONSTEXPR void pop_front(void);
REXY_CPP20_CONSTEXPR void resize(size_type count);
REXY_CPP20_CONSTEXPR void resize(size_type count, value_type value);
REXY_CPP20_CONSTEXPR void swap(list& other);
REXY_CPP20_CONSTEXPR void merge(list&& other);
template
REXY_CPP20_CONSTEXPR void merge(list&& other, Comp comp);
REXY_CPP20_CONSTEXPR void splice(const_iterator pos, list&& other);
REXY_CPP20_CONSTEXPR void splice(const_iterator pos, list&& other, const_iterator it);
REXY_CPP20_CONSTEXPR void splice(const_iterator pos, list&& other, const_iterator first, const_iterator last);
REXY_CPP20_CONSTEXPR size_type remove(const_reference value);
template
REXY_CPP20_CONSTEXPR size_type remove_if(UnaryPred p);
REXY_CPP20_CONSTEXPR void reverse(void)noexcept;
REXY_CPP20_CONSTEXPR size_type unique(void);
template
REXY_CPP20_CONSTEXPR size_type unique(BinaryPred p);
REXY_CPP20_CONSTEXPR void sort(void);
template
REXY_CPP20_CONSTEXPR void sort(Comp comp);
private:
template
iterator mergesort(iterator first, size_type firstlen, Comp comp);
std::pair ms_split(iterator it, size_type len);
static void insert_node_(detail::node_base* prev, detail::node_base* n);
static void remove_node_(detail::node_base* rm);
static detail::node_base* get_next_then_move_node_(detail::node_base* dest, detail::node_base* n);
constexpr auto& sentinel(void){return this->m_sentinel;}
constexpr const auto& sentinel(void)const{return this->m_sentinel;}
};
}
#include "list.tpp"
#endif