List#
Source file#
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
Allocatoris not required as template parameter.Use dummpy head and tail nodes to simplify the implementation.
Not a circular list (what libsdtc++ does).
Use
sizemember to support \(O(1)\)size()operation.
- 模板参数
T – Type of the elements stored in the nodes of list.
Public Types
-
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 const_reverse_iterator = std::reverse_iterator<const_iterator>#
Public Functions
-
List()#
-
~List()#
-
List &operator=(List &&other) noexcept(allocator_traits::propagate_on_container_move_assignment::value || allocator_traits::is_always_equal::value)#
-
allocator_type get_allocator() const noexcept#
-
const_iterator begin() const 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#
-
const_reference front() const#
-
const_reference back() const#
-
void pop_front()#
-
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)#
-
template<class UnaryPredicate>
size_type remove_if(UnaryPredicate pred)#
-
template<class BinaryPredicate>
size_type unique(BinaryPredicate binary_pred)#
-
void sort()#
-
void reverse() noexcept#