List#

Source file#

ChaiGO container/sequence/list

Interface#

template<ContainerElement T>
class List#

A doubly linked list.

A list is a sequence container that supports bidirectional iterators and allows constant time insert and erase operations anywhere within the sequence, with storage management handled automatically. Unlike vectors and deques, fast random access to list elements is not supported, but many algorithms only need sequential access anyway.

Difference

  • Allocator is not required as template parameter.

  • Use dummpy head and tail nodes to simplify the implementation.

  • Not a circular list (what libsdtc++ does).

  • Use size member to support \(O(1)\) size() operation.

模板参数

T – Type of the elements stored in the nodes of list.

Public Types

using value_type = T#
using node_type = ListNode<T>#
using allocator_type = allocator<node_type>#
using allocator_traits = std::allocator_traits<allocator_type>#
using pointer = typename allocator_traits::pointer#
using const_pointer = typename allocator_traits::const_pointer#
using reference = value_type&#
using const_reference = const value_type&#
using size_type = std::size_t#
using difference_type = std::ptrdiff_t#
using iterator = ListIterator<T>#
using const_iterator = ListConstIterator<T>#
using reverse_iterator = std::reverse_iterator<iterator>#
using const_reverse_iterator = std::reverse_iterator<const_iterator>#

Public Functions

List()#
explicit List(size_type count, const T &value = T())#
template<std::input_iterator InputIt>
List(InputIt first, InputIt last)#
List(const List &other)#
List(List &&other)#
List(std::initializer_list<T> ilist)#
~List()#
List &operator=(const List &other)#
List &operator=(List &&other) noexcept(allocator_traits::propagate_on_container_move_assignment::value || allocator_traits::is_always_equal::value)#
List &operator=(std::initializer_list<T> ilist)#
template<std::input_iterator InputIt>
void assign(InputIt first, InputIt last)#
void assign(size_type count, const T &value)#
void assign(std::initializer_list<T> ilist)#
allocator_type get_allocator() const noexcept#
iterator begin() noexcept#
const_iterator begin() const noexcept#
iterator end() noexcept#
const_iterator end() const noexcept#
reverse_iterator rbegin() noexcept#
const_reverse_iterator rbegin() const noexcept#
reverse_iterator rend() noexcept#
const_reverse_iterator rend() const noexcept#
const_iterator cbegin() const noexcept#
const_iterator cend() const noexcept#
const_reverse_iterator crbegin() const noexcept#
const_reverse_iterator crend() const noexcept#
bool empty() const noexcept#
size_type size() const noexcept#
size_type max_size() const noexcept#
void resize(size_type count)#
void resize(size_type count, const T &value)#
reference front()#
const_reference front() const#
reference back()#
const_reference back() const#
template<class ...Args>
reference emplace_front(Args&&... args)#
template<class ...Args>
reference emplace_back(Args&&... args)#
void push_front(const T &value)#
void push_front(T &&value)#
void pop_front()#
void push_back(const T &value)#
void push_back(T &&value)#
void pop_back()#
template<class ...Args>
iterator emplace(const_iterator pos, Args&&... args)#
iterator insert(const_iterator pos, const T &value)#
iterator insert(const_iterator pos, T &&value)#
iterator insert(const_iterator pos, size_type count, const T &value)#
template<std::input_iterator InputIt>
iterator insert(const_iterator pos, InputIt first, InputIt last)#
iterator insert(const_iterator pos, std::initializer_list<T> ilist)#
iterator erase(const_iterator pos)#
iterator erase(const_iterator first, const_iterator last)#
void swap(List &other) noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value)#
void clear() noexcept#
void splice(const_iterator pos, List &other)#
void splice(const_iterator pos, List &&other)#
void splice(const_iterator pos, List &other, const_iterator it)#
void splice(const_iterator pos, List &&other, const_iterator it)#
void splice(const_iterator pos, List &other, const_iterator first, const_iterator last)#
void splice(const_iterator pos, List &&other, const_iterator first, const_iterator last)#
size_type remove(const T &value)#
template<class UnaryPredicate>
size_type remove_if(UnaryPredicate pred)#
size_type unique()#
template<class BinaryPredicate>
size_type unique(BinaryPredicate binary_pred)#
void merge(List &other)#
void merge(List &&other)#
template<class Compare>
void merge(List &other, Compare comp)#
template<class Compare>
void merge(List &&other, Compare comp)#
void sort()#
template<class Compare>
void sort(Compare comp)#
void reverse() noexcept#