12 KiB
[queue]
23 Containers library [containers]
23.6 Container adaptors [container.adaptors]
23.6.3 Class template queue [queue]
23.6.3.1 Definition [queue.defn]
Any sequence container supporting operationsfront(),back(),push_back() andpop_front() can be used to instantiatequeue.
In particular, and can be used.
namespace std {template<class T, class Container = deque>class queue {public:using value_type = typename Container::value_type; using reference = typename Container::reference; using const_reference = typename Container::const_reference; using size_type = typename Container::size_type; using container_type = Container; protected: Container c; public:constexpr queue() : queue(Container()) {}constexpr explicit queue(const Container&); constexpr explicit queue(Container&&); template constexpr queue(InputIterator first, InputIterator last); template<container-compatible-range R> constexpr queue(from_range_t, R&& rg); template constexpr explicit queue(const Alloc&); template constexpr queue(const Container&, const Alloc&); template constexpr queue(Container&&, const Alloc&); template constexpr queue(const queue&, const Alloc&); template constexpr queue(queue&&, const Alloc&); template<class InputIterator, class Alloc>constexpr queue(InputIterator first, InputIterator last, const Alloc&); template<container-compatible-range R, class Alloc>constexpr queue(from_range_t, R&& rg, const Alloc&); constexpr bool empty() const { return c.empty(); }constexpr size_type size() const { return c.size(); }constexpr reference front() { return c.front(); }constexpr const_reference front() const { return c.front(); }constexpr reference back() { return c.back(); }constexpr const_reference back() const { return c.back(); }constexpr void push(const value_type& x) { c.push_back(x); }constexpr void push(value_type&& x) { c.push_back(std::move(x)); }template<container-compatible-range R> constexpr void push_range(R&& rg); template<class... Args>constexpr decltype(auto) emplace(Args&&... args){ return c.emplace_back(std::forward(args)...); }constexpr void pop() { c.pop_front(); }constexpr void swap(queue& q) noexcept(is_nothrow_swappable_v){ using std::swap; swap(c, q.c); }}; template queue(Container) -> queue<typename Container::value_type, Container>; template queue(InputIterator, InputIterator) -> queue<iter-value-type>; template<ranges::input_range R> queue(from_range_t, R&&) -> queue<ranges::range_value_t>; template<class Container, class Allocator> queue(Container, Allocator) -> queue<typename Container::value_type, Container>; template<class InputIterator, class Allocator> queue(InputIterator, InputIterator, Allocator)-> queue<iter-value-type, deque<iter-value-type, Allocator>>; template<ranges::input_range R, class Allocator> queue(from_range_t, R&&, Allocator)-> queue<ranges::range_value_t, deque<ranges::range_value_t, Allocator>>; template<class T, class Container, class Alloc>struct uses_allocator<queue<T, Container>, Alloc>: uses_allocator<Container, Alloc>::type { };}
23.6.3.2 Constructors [queue.cons]
constexpr explicit queue(const Container& cont);
Effects: Initializes c with cont.
constexpr explicit queue(Container&& cont);
Effects: Initializes c with std::move(cont).
template<class InputIterator> constexpr queue(InputIterator first, InputIterator last);
Effects: Initializes c withfirst as the first argument and last as the second argument.
template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]")<T> R> constexpr queue(from_range_t, R&& rg);
Effects: Initializes c with ranges::to(std::forward(rg)).
23.6.3.3 Constructors with allocators [queue.cons.alloc]
If uses_allocator_v<container_type, Alloc> is false the constructors in this subclause shall not participate in overload resolution.
template<class Alloc> constexpr explicit queue(const Alloc& a);
Effects: Initializes c with a.
template<class Alloc> constexpr queue(const container_type& cont, const Alloc& a);
Effects: Initializes c with cont as the first argument and a as the second argument.
template<class Alloc> constexpr queue(container_type&& cont, const Alloc& a);
Effects: Initializes c with std::move(cont) as the first argument and a as the second argument.
template<class Alloc> constexpr queue(const queue& q, const Alloc& a);
Effects: Initializes c with q.c as the first argument and a as the second argument.
template<class Alloc> constexpr queue(queue&& q, const Alloc& a);
Effects: Initializes c with std::move(q.c) as the first argument and a as the second argument.
template<class InputIterator, class Alloc> constexpr queue(InputIterator first, InputIterator last, const Alloc& alloc);
Effects: Initializes c withfirst as the first argument,last as the second argument, andalloc as the third argument.
template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]")<T> R, class Alloc> constexpr queue(from_range_t, R&& rg, const Alloc& a);
Effects: Initializes c withranges::to(std::forward(rg), a).
23.6.3.4 Modifiers [queue.mod]
template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]")<T> R> constexpr void push_range(R&& rg);
Effects: Equivalent to c.append_range(std::forward(rg)) if that is a valid expression, otherwise ranges::copy(rg, back_inserter(c)).
23.6.3.5 Operators [queue.ops]
template<class T, class Container> constexpr bool operator==(const queue<T, Container>& x, const queue<T, Container>& y);
Returns: x.c == y.c.
template<class T, class Container> constexpr bool operator!=(const queue<T, Container>& x, const queue<T, Container>& y);
Returns: x.c != y.c.
template<class T, class Container> constexpr bool operator< (const queue<T, Container>& x, const queue<T, Container>& y);
Returns: x.c < y.c.
template<class T, class Container> constexpr bool operator> (const queue<T, Container>& x, const queue<T, Container>& y);
Returns: x.c > y.c.
template<class T, class Container> constexpr bool operator<=(const queue<T, Container>& x, const queue<T, Container>& y);
Returns: x.c <= y.c.
template<class T, class Container> constexpr bool operator>=(const queue<T, Container>& x, const queue<T, Container>& y);
Returns: x.c >= y.c.
template<class T, [three_way_comparable](cmp.concept#concept:three_way_comparable "17.12.4 Concept three_way_comparable [cmp.concept]") Container> constexpr compare_three_way_result_t<Container> operator<=>(const queue<T, Container>& x, const queue<T, Container>& y);
Returns: x.c <=> y.c.
23.6.3.6 Specialized algorithms [queue.special]
template<class T, class Container> constexpr void swap(queue<T, Container>& x, queue<T, Container>& y) noexcept(noexcept(x.swap(y)));
Constraints: is_swappable_v is true.
Effects: As if by x.swap(y).