Namespaces
Variants

std::deque<T,Allocator>:: deque

From cppreference.net
deque ( ) : deque ( Allocator ( ) ) { }
(1) (seit C++11)
(constexpr seit C++26)
(2)
explicit deque ( const Allocator & alloc = Allocator ( ) ) ;
(bis C++11)
explicit deque ( const Allocator & alloc ) ;
(seit C++11)
(constexpr seit C++26)
explicit deque ( size_type count,
const Allocator & alloc = Allocator ( ) ) ;
(3) (seit C++11)
(constexpr seit C++26)
(4)
explicit deque ( size_type count, const T & value = T ( ) ,
const Allocator & alloc = Allocator ( ) ) ;
(bis C++11)
deque ( size_type count, const T & value,
const Allocator & alloc = Allocator ( ) ) ;
(seit C++11)
(constexpr seit C++26)
template < class InputIt >

deque ( InputIt first, InputIt last,

const Allocator & alloc = Allocator ( ) ) ;
(5) (constexpr seit C++26)
template < container-compatible-range < T > R >

deque ( std:: from_range_t , R && rg,

const Allocator & alloc = Allocator ( ) ) ;
(6) (seit C++23)
(constexpr seit C++26)
deque ( const deque & other ) ;
(7) (constexpr seit C++26)
deque ( deque && other ) ;
(8) (seit C++11)
(constexpr seit C++26)
(9)
deque ( const deque & other, const Allocator & alloc ) ;
(seit C++11)
(bis C++23)
deque ( const deque & other,
const std:: type_identity_t < Allocator > & alloc ) ;
(seit C++23)
(constexpr seit C++26)
(10)
deque ( deque && other, const Allocator & alloc ) ;
(seit C++11)
(bis C++23)
deque ( deque && other, const std:: type_identity_t < Allocator > & alloc ) ;
(seit C++23)
(constexpr seit C++26)
deque ( std:: initializer_list < T > init,
const Allocator & alloc = Allocator ( ) ) ;
(11) (seit C++11)
(constexpr seit C++26)

Konstruiert einen neuen deque aus verschiedenen Datenquellen, optional unter Verwendung einer benutzerdefinierten Zuweisung alloc .

1) Der Standardkonstruktor seit C++11. Konstruiert eine leere deque mit einem standardkonstruierten Allokator.
Wenn Allocator nicht DefaultConstructible ist, ist das Verhalten undefiniert.
2) Der Standardkonstruktor bis C++11. Konstruiert eine leere deque mit dem gegebenen Allokator alloc .
3) Konstruiert einen deque mit count standardmäßig eingefügten Objekten von T . Es werden keine Kopien erstellt.
Wenn T nicht DefaultInsertable in deque ist, ist das Verhalten undefiniert.
4) Konstruiert einen deque mit count Kopien von Elementen mit dem Wert value .

Falls T nicht CopyInsertable in den deque ist, ist das Verhalten undefiniert.

(seit C++11)
5) Konstruiert einen deque mit den Inhalten des Bereichs [ first , last ) . Jeder Iterator in [ first , last ) wird genau einmal dereferenziert.

Falls InputIt nicht die Anforderungen von LegacyInputIterator erfüllt, wird stattdessen Überladung (4) mit den Argumenten static_cast < size_type > ( first ) , last und alloc aufgerufen.

(bis C++11)

Diese Überladung nimmt nur dann an der Überladungsauflösung teil, wenn InputIt die Anforderungen von LegacyInputIterator erfüllt.

Falls T nicht EmplaceConstructible in deque von * first ist, ist das Verhalten undefiniert.

(seit C++11)
6) Konstruiert einen deque mit den Inhalten des Bereichs rg . Jeder Iterator in rg wird genau einmal dereferenziert.
Wenn T nicht EmplaceConstructible in deque von * ranges:: begin ( rg ) ist, ist das Verhalten undefiniert.
7) Der Kopierkonstruktor. Konstruiert einen deque mit den Inhalten von other .

Der Allokator wird bezogen, als ob durch Aufruf von
std:: allocator_traits < Allocator > :: select_on_container_copy_construction
( other. get_allocator ( ) )
.

(since C++11)
8) Der Move-Konstruktor. Konstruiert einen deque mit den Inhalten von other . Der Allokator wird durch Move-Konstruktion von other. get_allocator ( ) erhalten.
9) Gleich wie der Kopierkonstruktor, außer dass alloc als Allokator verwendet wird.
Falls T nicht CopyInsertable in deque ist, ist das Verhalten undefiniert.
10) Gleich wie der Move-Konstruktor, außer dass alloc als Allokator verwendet wird.
Wenn T nicht MoveInsertable in deque ist, ist das Verhalten undefiniert.
11) Entspricht deque ( il. begin ( ) , il. end ( ) , alloc ) .

Inhaltsverzeichnis

Parameter

alloc - Allokator, der für alle Speicherallokationen dieses Containers verwendet wird
count - die Größe des Containers
value - der Wert, mit dem Elemente des Containers initialisiert werden
first, last - das Iteratorenpaar, das den Quell- Bereich der zu kopierenden Elemente definiert
other - ein anderer Container, der als Quelle zur Initialisierung der Elemente des Containers verwendet wird
init - Initialisierungsliste zur Initialisierung der Elemente des Containers
rg - ein Container-kompatibler Bereich

Komplexität

1,2) Konstante.
3,4) Linear in count .
5) Linear in std:: distance ( first, last ) .
6) Linear in ranges:: distance ( rg ) .
7) Linear in other. size ( ) .
8) Konstante.
9) Linear in other. size ( ) .
10) Linear in other. size ( ) if alloc ! = other. get_allocator ( ) , ansonsten konstant.
11) Linear in init. size ( ) .

Ausnahmen

Aufrufe von Allocator :: allocate können eine Exception werfen.

Hinweise

Nach Container-Verschiebekonstruktion (Überladungen ( 8 ) und ( 10 ) ) bleiben Referenzen, Zeiger und Iteratoren (außer dem End-Iterator) auf other gültig, verweisen jedoch auf Elemente, die sich nun in * this befinden. Der aktuelle Standard gibt diese Garantie durch die pauschale Aussage in [container.reqmts]/67 , und eine direktere Garantie wird durch LWG issue 2321 in Betracht gezogen.

Feature-Test Makro Wert Std Feature
__cpp_lib_containers_ranges 202202L (C++23) Ranges-basierte Konstruktion und Einfügung; Überladung ( 6 )

Beispiel

#include <deque>
#include <iostream>
#include <string>
template<typename T>
std::ostream& operator<<(std::ostream& s, const std::deque<T>& v)
{
    s.put('{');
    for (char comma[]{'\0', ' ', '\0'}; const auto& e : v)
        s << comma << e, comma[0] = ',';
    return s << "}\n";
}
int main()
{
    // C++11 Initialisierungslisten-Syntax:
    std::deque<std::string> words1{"the", "frogurt", "is", "also", "cursed"};
    std::cout << "1: " << words1;
    // words2 == words1
    std::deque<std::string> words2(words1.begin(), words1.end());
    std::cout << "2: " << words2;
    // words3 == words1
    std::deque<std::string> words3(words1);
    std::cout << "3: " << words3;
    // words4 ist {"Mo", "Mo", "Mo", "Mo", "Mo"}
    std::deque<std::string> words4(5, "Mo");
    std::cout << "4: " << words4;
    const auto rg = {"cat", "cow", "crow"};
#ifdef __cpp_lib_containers_ranges
    std::deque<std::string> words5(std::from_range, rg); // Überladung (6)
#else
    std::deque<std::string> words5(rg.begin(), rg.end()); // Überladung (5)
#endif
    std::cout << "5: " << words5;
}

Ausgabe:

1: {the, frogurt, is, also, cursed}
2: {the, frogurt, is, also, cursed}
3: {the, frogurt, is, also, cursed}
4: {Mo, Mo, Mo, Mo, Mo}
5: {cat, cow, crow}

Fehlerberichte

Die folgenden verhaltensändernden Fehlerberichte wurden rückwirkend auf zuvor veröffentlichte C++-Standards angewendet.

DR Angewendet auf Verhalten wie veröffentlicht Korrigiertes Verhalten
LWG 144 C++98 Die Komplexitätsanforderung der Überladung ( 5 ) war identisch
mit der entsprechenden Überladung von std::vector
Auf lineare Komplexität geändert
LWG 237 C++98 Die Komplexitätsanforderung der Überladung
( 5 ) war linear in first - last
Geändert zu linear in
std:: distance ( first, last )
LWG 438 C++98 Überladung ( 5 ) würde nur Überladung ( 4 )
aufrufen, wenn InputIt ein integraler Typ ist
Ruft Überladung ( 4 ) auf, wenn InputIt
kein LegacyInputIterator ist
LWG 2193 C++11 Der Standardkonstruktor war explicit Auf non-explicit geändert
LWG 2210 C++11 Überladung ( 3 ) hatte keinen Allokator-Parameter Parameter hinzugefügt
N3346 C++11 Für Überladung ( 3 ) wurden die Elemente im
Container value-initialized
Sie sind default-inserted

Siehe auch

weist dem Container Werte zu
(öffentliche Elementfunktion)
weist dem Container Werte zu
(öffentliche Elementfunktion)