标准库标头 <deque>
来自cppreference.com
此头文件是容器库的一部分。
包含 | |
(C++20) |
三路比较运算符支持 |
(C++11) |
std::initializer_list 类模板 |
类 | |
双端队列 (类模板) | |
函数 | |
(C++20 中移除)(C++20 中移除)(C++20 中移除)(C++20 中移除)(C++20 中移除)(C++20) |
按照字典顺序比较 deque 中的值 (函数模板) |
特化 std::swap 算法 (函数模板) | |
擦除所有满足特定判别标准的元素 (函数模板) | |
范围访问 | |
(C++11)(C++14) |
返回指向容器或数组起始的迭代器 (函数模板) |
(C++11)(C++14) |
返回指向容器或数组结尾的迭代器 (函数模板) |
(C++14) |
返回指向一个容器或数组的逆向迭代器 (函数模板) |
(C++14) |
返回容器或数组的逆向尾迭代器 (函数模板) |
(C++17)(C++20) |
返回容器或数组的大小 (函数模板) |
(C++17) |
检查容器是否为空 (函数模板) |
(C++17) |
获得指向底层数组的指针 (函数模板) |
概要
#include <compare> #include <initializer_list> namespace std { // 类模板 deque template<class T, class Allocator = allocator<T>> class deque; template<class T, class Allocator> bool operator==(const deque<T, Allocator>& x, const deque<T, Allocator>& y); template<class T, class Allocator> /*synth-three-way-result*/<T> operator<=>(const deque<T, Allocator>& x, const deque<T, Allocator>& y); template<class T, class Allocator> void swap(deque<T, Allocator>& x, deque<T, Allocator>& y) noexcept(noexcept(x.swap(y))); template<class T, class Allocator, class U> typename deque<T, Allocator>::size_type erase(deque<T, Allocator>& c, const U& value); template<class T, class Allocator, class Predicate> typename deque<T, Allocator>::size_type erase_if(deque<T, Allocator>& c, Predicate pred); namespace pmr { template<class T> using deque = std::deque<T, polymorphic_allocator<T>>; } }
类模板 std::deque
namespace std { template<class T, class Allocator = allocator<T>> class deque { 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>; // 构造/复制/销毁 deque() : deque(Allocator()) { } explicit deque(const Allocator&); explicit deque(size_type n, const Allocator& = Allocator()); deque(size_type n, const T& value, const Allocator& = Allocator()); template<class InputIt> deque(InputIt first, InputIt last, const Allocator& = Allocator()); deque(const deque& x); deque(deque&&); deque(const deque&, const Allocator&); deque(deque&&, const Allocator&); deque(initializer_list<T>, const Allocator& = Allocator()); ~deque(); deque& operator=(const deque& x); deque& operator=(deque&& x) noexcept(allocator_traits<Allocator>::is_always_equal::value); deque& operator=(initializer_list<T>); template<class InputIt> void assign(InputIt first, InputIt last); 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; // 容量 [[nodiscard]] 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); void shrink_to_fit(); // 元素访问 reference operator[](size_type n); const_reference operator[](size_type n) const; reference at(size_type n); const_reference at(size_type n) const; 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); template<class... Args> iterator emplace(const_iterator position, Args&&... args); void push_front(const T& x); void push_front(T&& x); void push_back(const T& x); void push_back(T&& x); iterator insert(const_iterator position, const T& x); iterator insert(const_iterator position, T&& x); iterator insert(const_iterator position, size_type n, const T& x); template<class InputIt> iterator insert(const_iterator position, InputIt first, InputIt last); iterator insert(const_iterator position, initializer_list<T>); void pop_front(); void pop_back(); iterator erase(const_iterator position); iterator erase(const_iterator first, const_iterator last); void swap(deque&) noexcept(allocator_traits<Allocator>::is_always_equal::value); void clear() noexcept; }; template<class InputIt, class Allocator = allocator</*iter-value-type*/<InputIt>>> deque(InputIt, InputIt, Allocator = Allocator()) -> deque</*iter-value-type*/<InputIt>, Allocator>; // 交换 template<class T, class Allocator> void swap(deque<T, Allocator>& x, deque<T, Allocator>& y) noexcept(noexcept(x.swap(y))); }