This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

279
cppdraft/queue.md Normal file
View File

@@ -0,0 +1,279 @@
[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,<list> and<deque> can be used[.](#defn-1.sentence-2)
namespace std {template<class T, class Container = deque<T>>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<class InputIterator> constexpr queue(InputIterator first, InputIterator last); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R> constexpr queue(from_range_t, R&& rg); template<class Alloc> constexpr explicit queue(const Alloc&); template<class Alloc> constexpr queue(const Container&, const Alloc&); template<class Alloc> constexpr queue(Container&&, const Alloc&); template<class Alloc> constexpr queue(const queue&, const Alloc&); template<class Alloc> constexpr queue(queue&&, const Alloc&); template<class InputIterator, class Alloc>constexpr queue(InputIterator first, InputIterator last, const Alloc&); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> 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.1Introduction[container.intro.reqmts]")<T> R> constexpr void push_range(R&& rg); template<class... Args>constexpr decltype(auto) emplace(Args&&... args){ return c.emplace_back(std::forward<Args>(args)...); }constexpr void pop() { c.pop_front(); }constexpr void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>){ using std::swap; swap(c, q.c); }}; template<class Container> queue(Container) -> queue<typename Container::value_type, Container>; template<class InputIterator> queue(InputIterator, InputIterator) -> queue<*iter-value-type*<InputIterator>>; template<ranges::[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R> queue(from_range_t, R&&) -> queue<ranges::range_value_t<R>>; 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*<InputIterator>, deque<*iter-value-type*<InputIterator>,
Allocator>>; template<ranges::[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Allocator> queue(from_range_t, R&&, Allocator)-> queue<ranges::range_value_t<R>, deque<ranges::range_value_t<R>, Allocator>>; template<class T, class Container, class Alloc>struct uses_allocator<queue<T, Container>, Alloc>: uses_allocator<Container, Alloc>::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<class InputIterator>
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.1Introduction[container.intro.reqmts]")<T> 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<Container>(std::forward<R>(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<container_type, Alloc> is false the constructors in this subclause shall not participate in overload resolution[.](#cons.alloc-1.sentence-1)
[🔗](#lib:queue,constructor____)
`template<class Alloc> 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<class Alloc> 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<class Alloc> 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<class Alloc> 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<class Alloc> 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<class InputIterator, class Alloc>
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.1Introduction[container.intro.reqmts]")<T> 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<Container>(std::forward<R>(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.1Introduction[container.intro.reqmts]")<T> 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<R>(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<class T, class Container>
constexpr bool operator==(const queue<T, Container>& x, const queue<T, Container>& 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<class T, class Container>
constexpr bool operator!=(const queue<T, Container>& x, const queue<T, Container>& 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<class T, class Container>
constexpr bool operator< (const queue<T, Container>& x, const queue<T, Container>& 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<class T, class Container>
constexpr bool operator> (const queue<T, Container>& x, const queue<T, Container>& 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<class T, class Container>
constexpr bool operator<=(const queue<T, Container>& x, const queue<T, Container>& 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<class T, class Container>
constexpr bool operator>=(const queue<T, Container>& x, const queue<T, Container>& 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<class T, [three_way_comparable](cmp.concept#concept:three_way_comparable "17.12.4Concept three_­way_­comparable[cmp.concept]") Container>
constexpr compare_three_way_result_t<Container>
operator<=>(const queue<T, Container>& x, const queue<T, Container>& 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<class T, class Container>
constexpr void swap(queue<T, Container>& x, queue<T, Container>& y)
noexcept(noexcept(x.swap(y)));
`
[1](#special-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15980)
*Constraints*: is_swappable_v<Container> 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)