(C++17) | ||||
Sequence | ||||
(C++11) | ||||
(C++26) | ||||
(C++26) | ||||
(C++11) | ||||
Associative | ||||
Unordered associative | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
Adaptors | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
Views | ||||
(C++20) | ||||
(C++23) | ||||
Tables | ||||
Iterator invalidation | ||||
Member function table | ||||
Non-member function table |
std::queue
Member functions | ||||
queue::queue | ||||
Element access | ||||
Capacity | ||||
Modifiers | ||||
(C++23) | ||||
(C++11) | ||||
(C++11) | ||||
Non-member functions | ||||
(C++11) | ||||
Helper classes | ||||
(C++11) | ||||
(C++23) | ||||
Deduction guides(C++17) |
queue(): queue(Container()){} | (1) | (since C++11) |
(2) | ||
explicit queue(const Container& cont= Container()); | (until C++11) | |
explicit queue(const Container& cont); | (since C++11) | |
explicit queue( Container&& cont); | (3) | (since C++11) |
queue(const queue& other); | (4) | (implicitly declared) |
queue( queue&& other); | (5) | (since C++11) (implicitly declared) |
template<class InputIt> queue( InputIt first, InputIt last); | (6) | (since C++23) |
template<class Alloc> explicit queue(const Alloc& alloc); | (7) | (since C++11) |
template<class Alloc> queue(const Container& cont,const Alloc& alloc); | (8) | (since C++11) |
template<class Alloc> queue( Container&& cont,const Alloc& alloc); | (9) | (since C++11) |
template<class Alloc> queue(const queue& other,const Alloc& alloc); | (10) | (since C++11) |
template<class Alloc> queue( queue&& other,const Alloc& alloc); | (11) | (since C++11) |
template<class InputIt,class Alloc> queue( InputIt first, InputIt last,const Alloc& alloc); | (12) | (since C++23) |
template<container-compatible-range<T> R> queue(std::from_range_t, R&& rg); | (13) | (since C++23) |
template<container-compatible-range<T> R,class Alloc> queue(std::from_range_t, R&& rg,const Alloc& alloc); | (14) | (since C++23) |
Constructs new underlying container of the container adaptor from a variety of data sources.
[
first,
last)
. This overload participates in overload resolution only ifInputIt
satisfiesLegacyInputIterator.queue
).[
first,
last)
usingalloc as allocator, as if byc(first, last, alloc). This overload participates in overload resolution only ifInputIt
satisfiesLegacyInputIterator.Contents |
alloc | - | allocator to use for all memory allocations of the underlying container |
other | - | another container adaptor to be used as source to initialize the underlying container |
cont | - | container to be used as source to initialize the underlying container |
first, last | - | the pair of iterators defining the sourcerange of elements to initialize with |
rg | - | acontainer compatible range, that is, aninput_range whose elements are convertible toT |
Type requirements | ||
-Alloc must meet the requirements ofAllocator. | ||
-Container must meet the requirements ofContainer. The constructors taking an allocator parameter participate in overload resolution only ifContainer meets the requirements ofAllocatorAwareContainer. | ||
-InputIt must meet the requirements ofLegacyInputIterator. |
Same as the corresponding operation on the wrapped container.
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_adaptor_iterator_pair_constructor | 202106L | (C++23) | Iterator pair constructors forstd::queue andstd::stack; overloads(6) and(12) |
__cpp_lib_containers_ranges | 202202L | (C++23) | Ranges-aware construction and insertion; overloads(13) and(14) |
#include <cassert>#include <deque>#include <iostream>#include <memory>#include <ranges>#include <queue> int main(){std::queue<int> c1; c1.push(5);assert(c1.size()==1); std::queue<int> c2(c1);assert(c2.size()==1); std::deque<int> deq{3,1,4,1,5};std::queue<int> c3(deq);// overload (2)assert(c3.size()==5); # ifdef __cpp_lib_adaptor_iterator_pair_constructorconstauto il={2,7,1,8,2};std::queue<int> c4{il.begin(), il.end()};// C++23, (6)assert(c4.size()==5);# endif # if __cpp_lib_containers_ranges >= 202202L// C++23, overload (13)auto c5=std::queue(std::from_range_t, std::ranges::iota(0,42));assert(c5.size()==42); // the same effect with pipe syntax, internally uses overload (13)auto c6= std::ranges::iota(0,42)| std::ranges::to<std::queue>();assert(c6.size()==42); std::allocator<int> alloc; // C++23, overload (14)auto c7=std::queue(std::from_range_t, std::ranges::iota(0,42), alloc);assert(c7.size()==42); // the same effect with pipe syntax, internally uses overload (14)auto c8= std::ranges::iota(0,42)| std::ranges::to<std::queue>(alloc);assert(c8.size()==42);# endif}
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
P0935R0 | C++11 | default constructor was explicit | made implicit |
assigns values to the container adaptor (public member function)[edit] |