Files
2025-10-25 03:02:53 +03:00

8.0 KiB

[deque.overview]

23 Containers library [containers]

23.3 Sequence containers [sequences]

23.3.5 Class template deque [deque]

23.3.5.1 Overview [deque.overview]

1

#

Adeque is a sequence container that supports random access iterators.

In addition, it supports constant time insert and erase operations at the beginning or the end; insert and erase in the middle take linear time.

That is, a deque is especially optimized for pushing and popping elements at the beginning and end.

Storage management is handled automatically.

2

#

A deque meets all of the requirements of a container ([container.reqmts]), of a reversible container ([container.rev.reqmts]), of an allocator-aware container ([container.alloc.reqmts]), and of a sequence container, including the optional sequence container requirements ([sequence.reqmts]).

Descriptions are provided here only for operations ondeque that are not described in one of these tables or for operations where there is additional semantic information.

3

#

The types iterator and const_iterator meet the constexpr iterator requirements ([iterator.requirements.general]).

namespace std {template<class T, class Allocator = allocator>class deque {public:// typesusing value_type = T; using allocator_type = Allocator; 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 = implementation-defined; // see [container.requirements]using difference_type = implementation-defined; // see [container.requirements]using iterator = implementation-defined; // see [container.requirements]using const_iterator = implementation-defined; // see [container.requirements]using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator<const_iterator>; // [deque.cons], construct/copy/destroyconstexpr deque() : deque(Allocator()) { }constexpr explicit deque(const Allocator&); constexpr explicit deque(size_type n, const Allocator& = Allocator()); constexpr deque(size_type n, const T& value, const Allocator& = Allocator()); templateconstexpr deque(InputIterator first, InputIterator last, const Allocator& = Allocator()); template<container-compatible-range R>constexpr deque(from_range_t, R&& rg, const Allocator& = Allocator()); constexpr deque(const deque& x); constexpr deque(deque&&); constexpr deque(const deque&, const type_identity_t&); constexpr deque(deque&&, const type_identity_t&); constexpr deque(initializer_list, const Allocator& = Allocator()); constexpr ~deque(); constexpr deque& operator=(const deque& x); constexpr deque& operator=(deque&& x)noexcept(allocator_traits::is_always_equal::value); constexpr deque& operator=(initializer_list); templateconstexpr void assign(InputIterator first, InputIterator last); template<container-compatible-range R>constexpr void assign_range(R&& rg); constexpr void assign(size_type n, const T& t); constexpr void assign(initializer_list); constexpr allocator_type get_allocator() const noexcept; // iteratorsconstexpr iterator begin() noexcept; constexpr const_iterator begin() const noexcept; constexpr iterator end() noexcept; constexpr const_iterator end() const noexcept; constexpr reverse_iterator rbegin() noexcept; constexpr const_reverse_iterator rbegin() const noexcept; constexpr reverse_iterator rend() noexcept; constexpr const_reverse_iterator rend() const noexcept; constexpr const_iterator cbegin() const noexcept; constexpr const_iterator cend() const noexcept; constexpr const_reverse_iterator crbegin() const noexcept; constexpr const_reverse_iterator crend() const noexcept; // [deque.capacity], capacityconstexpr bool empty() const noexcept; constexpr size_type size() const noexcept; constexpr size_type max_size() const noexcept; constexpr void resize(size_type sz); constexpr void resize(size_type sz, const T& c); constexpr void shrink_to_fit(); // element accessconstexpr reference operator[](size_type n); constexpr const_reference operator[](size_type n) const; constexpr reference at(size_type n); constexpr const_reference at(size_type n) const; constexpr reference front(); constexpr const_reference front() const; constexpr reference back(); constexpr const_reference back() const; // [deque.modifiers], modifierstemplate<class... Args> constexpr reference emplace_front(Args&&... args); template<class... Args> constexpr reference emplace_back(Args&&... args); template<class... Args> constexpr iterator emplace(const_iterator position, Args&&... args); constexpr void push_front(const T& x); constexpr void push_front(T&& x); template<container-compatible-range R>constexpr void prepend_range(R&& rg); constexpr void push_back(const T& x); constexpr void push_back(T&& x); template<container-compatible-range R>constexpr void append_range(R&& rg); constexpr iterator insert(const_iterator position, const T& x); constexpr iterator insert(const_iterator position, T&& x); constexpr iterator insert(const_iterator position, size_type n, const T& x); templateconstexpr iterator insert(const_iterator position, InputIterator first, InputIterator last); template<container-compatible-range R>constexpr iterator insert_range(const_iterator position, R&& rg); constexpr iterator insert(const_iterator position, initializer_list); constexpr void pop_front(); constexpr void pop_back(); constexpr iterator erase(const_iterator position); constexpr iterator erase(const_iterator first, const_iterator last); constexpr void swap(deque&)noexcept(allocator_traits::is_always_equal::value); constexpr void clear() noexcept; }; template<class InputIterator, class Allocator = allocator<iter-value-type>> deque(InputIterator, InputIterator, Allocator = Allocator())-> deque<iter-value-type, Allocator>; template<ranges::input_range R, class Allocator = allocator<ranges::range_value_t>> deque(from_range_t, R&&, Allocator = Allocator())-> deque<ranges::range_value_t, Allocator>;}