std::stack<T,Container>::stack
Von de.cppreference.net
stack() : stack(Container()) {}
|
(1) | (seit C++11) |
explicit stack( const Container& cont = Container() );
|
(2) | (bis C++11) |
explicit stack( const Container& cont );
|
(seit C++11) | |
explicit stack( Container&& cont );
|
(3) | (seit C++11) |
stack( const stack& other );
|
(4) | (implizit deklariert) |
stack( stack&& other );
|
(5) | (seit C++11) (implizit deklariert) |
template< class InputIt >
stack( InputIt first, InputIt last );
|
(6) | (seit C++23) |
template< class Alloc >
explicit stack( const Alloc& alloc );
|
(7) | (seit C++11) |
template< class Alloc >
stack( const Container& cont, const Alloc& alloc );
|
(8) | (seit C++11) |
template< class Alloc >
stack( Container&& cont, const Alloc& alloc );
|
(9) | (seit C++11) |
template< class Alloc >
stack( const stack& other, const Alloc& alloc );
|
(10) | (seit C++11) |
template< class Alloc >
stack( stack&& other, const Alloc& alloc );
|
(11) | (seit C++11) |
template< class InputIt, class Alloc >
stack( InputIt first, InputIt last, const Alloc& alloc );
|
(12) | (seit C++23) |
template< container-compatible-range<T> R>
stack( std::from_range_t, R&& rg );
|
(13) | (seit C++23) |
template< container-compatible-range<T> R, class Alloc >
stack( std::from_range_t, R&& rg, const Alloc& alloc );
|
(14) | (seit C++23) |
Konstruiert einen neuen zugrunde liegenden Container des Containeradapters aus einer Vielzahl von Datenquellen.
1) Standardkonstruktor. Wertinitialisiert den Container.
2) Kopierkonstruktion des zugrunde liegenden Containers
c mit dem Inhalt von cont. Dies ist auch der Standardkonstruktor.(bis C++11)3) Verschiebekonstruktion des zugrunde liegenden Containers
c mit std::move(cont).6) Konstruiert den zugrunde liegenden Container
c mit dem Inhalt des Bereichs [first, last). Diese Überladung nimmt nur an der Überladungsauflösung teil, wenn InputIt LegacyInputIterator erfüllt.7-12) Diese Konstruktoren nehmen nur an der Überladungsauflösung teil, wenn
std::uses_allocator<Container, Alloc>::value true ist, d. h. wenn der zugrunde liegende Container ein Allocator-bewusster Container ist (gilt für alle Standardbibliothekscontainer, die mit stack verwendet werden können).7) Konstruiert den zugrunde liegenden Container unter Verwendung von
alloc als Allokator, wie durch c(alloc).8) Konstruiert den zugrunde liegenden Container mit dem Inhalt von
cont und unter Verwendung von alloc als Allokator, wie durch c(cont, alloc).9) Konstruiert den zugrunde liegenden Container mit dem Inhalt von
cont unter Verwendung von Verschiebesemantik, während alloc als Allokator verwendet wird, wie durch c(std::move(cont), alloc).10) Konstruiert den Adapter mit dem Inhalt von
other.c und unter Verwendung von alloc als Allokator, wie durch c(other.c, alloc).11) Konstruiert den Adapter mit dem Inhalt von
other unter Verwendung von Verschiebesemantik, während alloc als Allokator verwendet wird, wie durch c(std::move(other.c), alloc).12) Konstruiert den zugrunde liegenden Container mit dem Inhalt des Bereichs
[first, last) unter Verwendung von alloc als Allokator, wie durch c(first, last, alloc). Diese Überladung nimmt nur an der Überladungsauflösung teil, wenn InputIt LegacyInputIterator erfüllt.13) Konstruiert den zugrunde liegenden Container mit
ranges::to<Container>(std::forward<R>(rg)).14) Konstruiert den zugrunde liegenden Container mit
ranges::to<Container>(std::forward<R>(rg), alloc).Parameter
| alloc | - | Allokator, der für alle Speicherallokationen des zugrundeliegenden Containers verwendet wird |
| other | - | ein weiterer Container-Adapter, der als Quelle zur Initialisierung des zugrundeliegenden Containers dient |
| cont | - | Container, der als Quelle zur Initialisierung des zugrundeliegenden Containers verwendet wird |
| first, last | - | das Iteratorpaar, das die Quell- Range der zu initialisierenden Elemente definiert |
| rg | - |
eine
containerkompatible 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 | Feature |
|---|---|---|---|
__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 <stack> int main() { std::stack<int> c1; c1.push(5); assert(c1.size() == 1); std::stack<int> c2(c1); assert(c2.size() == 1); std::deque<int> deq{3, 1, 4, 1, 5}; std::stack<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::stack<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::stack(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::stack>(); assert(c6.size() == 42); std::allocator<int> alloc; // C++23, Überladung (14) auto c7 = std::stack(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::stack>(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) |