std::queue<T,Container>:: queue
From cppreference.net
|
queue
(
)
:
queue
(
Container
(
)
)
{
}
|
(1) | (seit C++11) |
| (2) | ||
|
explicit
queue
(
const
Container
&
cont
=
Container
(
)
)
;
|
(bis C++11) | |
|
explicit
queue
(
const
Container
&
cont
)
;
|
(seit C++11) | |
|
explicit
queue
(
Container
&&
cont
)
;
|
(3) | (seit C++11) |
|
queue
(
const
queue
&
other
)
;
|
(4) | (implizit deklariert) |
|
queue
(
queue
&&
other
)
;
|
(5) |
(seit C++11)
(implizit deklariert) |
|
template
<
class
InputIt
>
queue ( InputIt first, InputIt last ) ; |
(6) | (seit C++23) |
|
template
<
class
Alloc
>
explicit queue ( const Alloc & alloc ) ; |
(7) | (seit C++11) |
|
template
<
class
Alloc
>
queue ( const Container & cont, const Alloc & alloc ) ; |
(8) | (seit C++11) |
|
template
<
class
Alloc
>
queue ( Container && cont, const Alloc & alloc ) ; |
(9) | (seit C++11) |
|
template
<
class
Alloc
>
queue ( const queue & other, const Alloc & alloc ) ; |
(10) | (seit C++11) |
|
template
<
class
Alloc
>
queue ( queue && other, const Alloc & alloc ) ; |
(11) | (seit C++11) |
|
template
<
class
InputIt,
class
Alloc
>
queue ( InputIt first, InputIt last, const Alloc & alloc ) ; |
(12) | (seit C++23) |
|
template
<
container-compatible-range
<
T
>
R
>
queue ( std:: from_range_t , R && rg ) ; |
(13) | (seit C++23) |
|
template
<
container-compatible-range
<
T
>
R,
class
Alloc
>
queue ( std:: from_range_t , R && rg, const Alloc & alloc ) ; |
(14) | (seit C++23) |
Konstruiert einen neuen zugrundeliegenden Container des Container-Adapters aus einer Vielzahl von Datenquellen.
1)
Standardkonstruktor. Wertinitialisiert den Container.
2)
Kopierkonstruiert den zugrundeliegenden Container
c
mit den Inhalten von
cont
.
Dies ist ebenfalls der Standardkonstruktor.
(bis C++11)
3)
Bewegt-konstruiert den zugrundeliegenden Container
c
mit
std
::
move
(
cont
)
.
6)
Konstruiert den zugrundeliegenden Container
c
mit den Inhalten des Bereichs
[
first
,
last
)
. Diese Überladung nimmt nur dann an der Überladungsauflösung teil, wenn
InputIt
die Anforderungen eines
LegacyInputIterator
erfüllt.
7-12)
Diese Konstruktoren nehmen nur dann an der Überlagerungsauflösung teil, wenn
std::
uses_allocator
<
Container, Alloc
>
::
value
gleich
true
ist, das heißt, wenn der zugrundeliegende Container ein allocator-aware Container ist (zutreffend für alle Standardbibliothekscontainer, die mit
queue
verwendet werden können).
7)
Konstruiert den zugrundeliegenden Container mit
alloc
als Allokator, als ob durch
c
(
alloc
)
.
8)
Konstruiert den zugrundeliegenden Container mit dem Inhalt von
cont
und verwendet
alloc
als Allokator, wie durch
c
(
cont, alloc
)
.
9)
Konstruiert den zugrundeliegenden Container mit dem Inhalt von
cont
unter Verwendung von Move-Semantik, wobei
alloc
als Allokator verwendet wird, wie durch
c
(
std
::
move
(
cont
)
, alloc
)
.
10)
Konstruiert den Adapter mit dem Inhalt von
other.
c
und verwendet
alloc
als Allokator, wie durch
c
(
other.
c
, alloc
)
.
11)
Konstruiert den Adapter mit den Inhalten von
other
unter Verwendung von Move-Semantik, wobei
alloc
als Allokator verwendet wird, wie durch
c
(
std
::
move
(
other.
c
)
, alloc
)
.
12)
Konstruiert den zugrundeliegenden Container mit den Inhalten des Bereichs
[
first
,
last
)
unter Verwendung von
alloc
als Allokator, wie durch
c
(
first, last, alloc
)
. Diese Überladung nimmt nur dann an der Überladungsauflösung teil, wenn
InputIt
die Anforderungen eines
LegacyInputIterator
erfüllt.
13)
Konstruiert den zugrundeliegenden Container mit
ranges::
to
<
Container
>
(
std::
forward
<
R
>
(
rg
)
)
.
14)
Konstruiert den zugrundeliegenden Container mit
ranges::
to
<
Container
>
(
std::
forward
<
R
>
(
rg
)
, alloc
)
.
Inhaltsverzeichnis |
Parameter
| alloc | - | Allokator, der für alle Speicherallokationen des zugrunde liegenden Containers verwendet wird |
| other | - | ein weiterer Container-Adapter, der als Quelle zur Initialisierung des zugrunde liegenden Containers dient |
| cont | - | Container, der als Quelle zur Initialisierung des zugrunde liegenden Containers verwendet wird |
| first, last | - | das Iteratorpaar, das die Quell- Range der zu initialisierenden Elemente definiert |
| rg | - |
eine
container-kompatible Range
, also ein
input_range
, dessen Elemente in
T
konvertierbar sind
|
| Typanforderungen | ||
-
Alloc
muss die Anforderungen von
Allocator
erfüllen.
|
||
-
Container
muss die Anforderungen von
Container
erfüllen. Die Konstruktoren mit einem Allokator-Parameter nehmen nur dann an der Überladungsauflösung teil, wenn
Container
die Anforderungen von
AllocatorAwareContainer
erfüllt.
|
||
-
InputIt
muss die Anforderungen von
LegacyInputIterator
erfüllen.
|
||
Komplexität
Gleich wie die entsprechende Operation auf dem umschlossenen Container.
Hinweise
| Feature-Test Makro | Wert | Std | Funktion |
|---|---|---|---|
__cpp_lib_adaptor_iterator_pair_constructor
|
202106L
|
(C++23) | Iterator-Paar-Konstruktoren für std::queue und std::stack ; Überladungen ( 6 ) und ( 12 ) |
__cpp_lib_containers_ranges
|
202202L
|
(C++23) | Ranges-basierte Konstruktion und Einfügung; Überladungen ( 13 ) und ( 14 ) |
Beispiel
Diesen Code ausführen
#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); // Überladung (2) assert(c3.size() == 5); # ifdef __cpp_lib_adaptor_iterator_pair_constructor const auto 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, Überladung (13) auto c5 = std::queue(std::from_range_t, std::ranges::iota(0, 42)); assert(c5.size() == 42); // gleicher Effekt mit Pipe-Syntax, verwendet intern Überladung (13) auto c6 = std::ranges::iota(0, 42) | std::ranges::to<std::queue>(); assert(c6.size() == 42); std::allocator<int> alloc; // C++23, Überladung (14) auto c7 = std::queue(std::from_range_t, std::ranges::iota(0, 42), alloc); assert(c7.size() == 42); // gleicher Effekt mit Pipe-Syntax, verwendet intern Überladung (14) auto c8 = std::ranges::iota(0, 42) | std::ranges::to<std::queue>(alloc); assert(c8.size() == 42); # endif }
Fehlerberichte
Die folgenden verhaltensändernden Fehlerberichte wurden rückwirkend auf zuvor veröffentlichte C++-Standards angewendet.
| DR | Angewendet auf | Verhalten wie veröffentlicht | Korrektes Verhalten |
|---|---|---|---|
| P0935R0 | C++11 | Standardkonstruktor war explicit | implizit gemacht |
Siehe auch
|
weist Werte dem Container-Adapter zu
(öffentliche Elementfunktion) |