Namespaces
Variants

Standard library header <list>

From cppreference.net
Standard library headers

此头文件属于 容器 库的一部分。

目录

包含文件

(C++20)
三路比较运算符 支持
std::initializer_list 类模板

双向链表
(类模板)

函数

(C++20 中移除) (C++20 中移除) (C++20 中移除) (C++20 中移除) (C++20 中移除) (C++20)
按字典序比较两个 list 的值
(函数模板)
特化 std::swap 算法
(函数模板)
擦除满足特定条件的所有元素
(函数模板)
范围访问
(C++11) (C++14)
返回指向容器或数组起始位置的迭代器
(函数模板)
(C++11) (C++14)
返回指向容器或数组末尾的迭代器
(函数模板)
返回指向容器或数组起始位置的反向迭代器
(函数模板)
(C++14)
返回容器或数组的逆向末尾迭代器
(函数模板)
(C++17) (C++20)
返回容器或数组的大小
(函数模板)
(C++17)
检查容器是否为空
(函数模板)
(C++17)
获取底层数组的指针
(函数模板)

概要

#include <compare>
#include <initializer_list>
namespace std {
  // 类模板 list
  template<class T, class Allocator = allocator<T>>
  class list;
  template<class T, class Allocator>
  bool operator==(const list<T, Allocator>& x, const list<T, Allocator>& y);
  template<class T, class Allocator>
  /*synth-three-way-result*/<T> operator<=>(const list<T, Allocator>& x,
                                            const list<T, Allocator>& y);
  template<class T, class Allocator>
  void swap(list<T, Allocator>& x, list<T, Allocator>& y) noexcept(noexcept(x.swap(y)));
  // 擦除操作
  template<class T, class Allocator, class U = T>
  typename list<T, Allocator>::size_type erase(list<T, Allocator>& c, const U& value);
  template<class T, class Allocator, class Predicate>
  typename list<T, Allocator>::size_type erase_if(list<T, Allocator>& c, Predicate pred);
  namespace pmr {
    template<class T>
    using list = std::list<T, polymorphic_allocator<T>>;
  }
}

类模板 std::list

namespace std {
  template<class T, class Allocator = allocator<T>>
  class list
  {
  public:
    // 类型定义
    using value_type             = T;
    using allocator_type         = Allocator;
    using pointer                = typename allocator_traits<Allocator>::pointer;
    using const_pointer          = typename allocator_traits<Allocator>::const_pointer;
    using reference              = value_type&;
    using const_reference        = const value_type&;
    using size_type              = /* 实现定义 */;
    using difference_type        = /* 实现定义 */;
    using iterator               = /* 实现定义 */;
    using const_iterator         = /* 实现定义 */;
    using reverse_iterator       = std::reverse_iterator<iterator>;
    using const_reverse_iterator = std::reverse_iterator<const_iterator>;
    // 构造/复制/销毁
    list()
      : list(Allocator())
    {
    }
    explicit list(const Allocator&);
    explicit list(size_type n, const Allocator& = Allocator());
    list(size_type n, const T& value, const Allocator& = Allocator());
    template<class InputIter>
    list(InputIter first, InputIter last, const Allocator& = Allocator());
    template<container-compatible-range<T> R>
    list(from_range_t, R&& rg, const Allocator& = Allocator());
    list(const list& x);
    list(list&& x);
    list(const list&, const type_identity_t<Allocator>&);
    list(list&&, const type_identity_t<Allocator>&);
    list(initializer_list<T>, const Allocator& = Allocator());
    ~list();
    list& operator=(const list& x);
    list& operator=(list&& x) noexcept(
      allocator_traits<Allocator>::is_always_equal::value);
    list& operator=(initializer_list<T>);
    template<class InputIter>
    void assign(InputIter first, InputIter last);
    template<container-compatible-range<T> R>
    void assign_range(R&& rg);
    void assign(size_type n, const T& t);
    void assign(initializer_list<T>);
    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 sz);
    void resize(size_type sz, const T& c);
    // 元素访问
    reference front();
    const_reference front() const;
    reference back();
    const_reference back() const;
    // 修改器
    template<class... Args>
    reference emplace_front(Args&&... args);
    template<<span class