[queue] # 23 Containers library [[containers]](./#containers) ## 23.6 Container adaptors [[container.adaptors]](container.adaptors#queue) ### 23.6.3 Class template queue [queue] #### [23.6.3.1](#defn) Definition [[queue.defn]](queue.defn) [1](#defn-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15635) Any sequence container supporting operationsfront(),back(),push_back() andpop_front() can be used to instantiatequeue[.](#defn-1.sentence-1) In particular, and can be used[.](#defn-1.sentence-2) namespace std {template>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*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") 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&); templateconstexpr queue(InputIterator first, InputIterator last, const Alloc&); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") 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*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") R> constexpr void push_range(R&& rg); templateconstexpr 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; template queue(InputIterator, InputIterator) -> queue<*iter-value-type*>; template queue(from_range_t, R&&) -> queue>; template queue(Container, Allocator) -> queue; template queue(InputIterator, InputIterator, Allocator)-> queue<*iter-value-type*, deque<*iter-value-type*, Allocator>>; template queue(from_range_t, R&&, Allocator)-> queue, deque, Allocator>>; templatestruct uses_allocator, Alloc>: uses_allocator::type { };} #### [23.6.3.2](#cons) Constructors [[queue.cons]](queue.cons) [🔗](#lib:queue,constructor) `constexpr explicit queue(const Container& cont); ` [1](#cons-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15733) *Effects*: Initializes c with cont[.](#cons-1.sentence-1) [🔗](#lib:queue,constructor_) `constexpr explicit queue(Container&& cont); ` [2](#cons-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15744) *Effects*: Initializes c with std​::​move(cont)[.](#cons-2.sentence-1) [🔗](#lib:queue,constructor__) `template constexpr queue(InputIterator first, InputIterator last); ` [3](#cons-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15756) *Effects*: Initializes c withfirst as the first argument and last as the second argument[.](#cons-3.sentence-1) [🔗](#lib:queue,constructor___) `template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") R> constexpr queue(from_range_t, R&& rg); ` [4](#cons-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15769) *Effects*: Initializes c with ranges​::​to(std​::​forward(rg))[.](#cons-4.sentence-1) #### [23.6.3.3](#cons.alloc) Constructors with allocators [[queue.cons.alloc]](queue.cons.alloc) [1](#cons.alloc-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15776) If uses_allocator_v is false the constructors in this subclause shall not participate in overload resolution[.](#cons.alloc-1.sentence-1) [🔗](#lib:queue,constructor____) `template constexpr explicit queue(const Alloc& a); ` [2](#cons.alloc-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15786) *Effects*: Initializes c with a[.](#cons.alloc-2.sentence-1) [🔗](#lib:queue,constructor_____) `template constexpr queue(const container_type& cont, const Alloc& a); ` [3](#cons.alloc-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15797) *Effects*: Initializes c with cont as the first argument and a as the second argument[.](#cons.alloc-3.sentence-1) [🔗](#lib:queue,constructor______) `template constexpr queue(container_type&& cont, const Alloc& a); ` [4](#cons.alloc-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15809) *Effects*: Initializes c with std​::​move(cont) as the first argument and a as the second argument[.](#cons.alloc-4.sentence-1) [🔗](#lib:queue,constructor_______) `template constexpr queue(const queue& q, const Alloc& a); ` [5](#cons.alloc-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15821) *Effects*: Initializes c with q.c as the first argument and a as the second argument[.](#cons.alloc-5.sentence-1) [🔗](#lib:queue,constructor________) `template constexpr queue(queue&& q, const Alloc& a); ` [6](#cons.alloc-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15833) *Effects*: Initializes c with std​::​move(q.c) as the first argument and a as the second argument[.](#cons.alloc-6.sentence-1) [🔗](#lib:queue,constructor_________) `template constexpr queue(InputIterator first, InputIterator last, const Alloc& alloc); ` [7](#cons.alloc-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15846) *Effects*: Initializes c withfirst as the first argument,last as the second argument, andalloc as the third argument[.](#cons.alloc-7.sentence-1) [🔗](#lib:queue,constructor__________) `template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") R, class Alloc> constexpr queue(from_range_t, R&& rg, const Alloc& a); ` [8](#cons.alloc-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15861) *Effects*: Initializes c withranges​::​to(std​::​forward(rg), a)[.](#cons.alloc-8.sentence-1) #### [23.6.3.4](#mod) Modifiers [[queue.mod]](queue.mod) [🔗](#lib:push_range,queue) `template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") R> constexpr void push_range(R&& rg); ` [1](#mod-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15876) *Effects*: Equivalent to c.append_range(std​::​forward(rg)) if that is a valid expression, otherwise ranges​::​copy(rg, back_inserter(c))[.](#mod-1.sentence-1) #### [23.6.3.5](#ops) Operators [[queue.ops]](queue.ops) [🔗](#lib:operator==,queue) `template constexpr bool operator==(const queue& x, const queue& y); ` [1](#ops-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15892) *Returns*: x.c == y.c[.](#ops-1.sentence-1) [🔗](#lib:operator!=,queue) `template constexpr bool operator!=(const queue& x, const queue& y); ` [2](#ops-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15904) *Returns*: x.c != y.c[.](#ops-2.sentence-1) [🔗](#lib:operator%3c,queue) `template constexpr bool operator< (const queue& x, const queue& y); ` [3](#ops-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15916) *Returns*: x.c < y.c[.](#ops-3.sentence-1) [🔗](#lib:operator%3e,queue) `template constexpr bool operator> (const queue& x, const queue& y); ` [4](#ops-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15928) *Returns*: x.c > y.c[.](#ops-4.sentence-1) [🔗](#lib:operator%3c=,queue) `template constexpr bool operator<=(const queue& x, const queue& y); ` [5](#ops-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15940) *Returns*: x.c <= y.c[.](#ops-5.sentence-1) [🔗](#lib:operator%3e=,queue) `template constexpr bool operator>=(const queue& x, const queue& y); ` [6](#ops-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15952) *Returns*: x.c >= y.c[.](#ops-6.sentence-1) [🔗](#lib:operator%3c=%3e,queue) `template constexpr compare_three_way_result_t operator<=>(const queue& x, const queue& y); ` [7](#ops-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15965) *Returns*: x.c <=> y.c[.](#ops-7.sentence-1) #### [23.6.3.6](#special) Specialized algorithms [[queue.special]](queue.special) [🔗](#lib:swap,queue) `template constexpr void swap(queue& x, queue& y) noexcept(noexcept(x.swap(y))); ` [1](#special-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15980) *Constraints*: is_swappable_v is true[.](#special-1.sentence-1) [2](#special-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15984) *Effects*: As if by x.swap(y)[.](#special-2.sentence-1)