std::list<T,Allocator>:: list
|
list
(
)
:
list
(
Allocator
(
)
)
{
}
|
(1) |
(seit C++11)
(constexpr seit C++26) |
| (2) | ||
|
explicit
list
(
const
Allocator
&
alloc
=
Allocator
(
)
)
;
|
(bis C++11) | |
|
explicit
list
(
const
Allocator
&
alloc
)
;
|
(seit C++11)
(constexpr seit C++26) |
|
|
explicit
list
(
size_type count,
const Allocator & alloc = Allocator ( ) ) ; |
(3) |
(seit C++11)
(constexpr seit C++26) |
| (4) | ||
|
explicit
list
(
size_type count,
const
T
&
value
=
T
(
)
,
const Allocator & alloc = Allocator ( ) ) ; |
(bis C++11) | |
|
list
(
size_type count,
const
T
&
value,
const Allocator & alloc = Allocator ( ) ) ; |
(seit C++11)
(constexpr seit C++26) |
|
|
template
<
class
InputIt
>
list
(
InputIt first, InputIt last,
|
(5) | (constexpr seit C++26) |
|
template
<
container-compatible-range
<
T
>
R
>
list
(
std::
from_range_t
, R
&&
rg,
|
(6) |
(seit C++23)
(constexpr seit C++26) |
|
list
(
const
list
&
other
)
;
|
(7) | (constexpr seit C++26) |
|
list
(
list
&&
other
)
;
|
(8) |
(seit C++11)
(constexpr seit C++26) |
| (9) | ||
|
list
(
const
list
&
other,
const
Allocator
&
alloc
)
;
|
(seit C++11)
(bis C++23) |
|
|
list
(
const
list
&
other,
const std:: type_identity_t < Allocator > & alloc ) ; |
(seit C++23)
(constexpr seit C++26) |
|
| (10) | ||
|
list
(
list
&&
other,
const
Allocator
&
alloc
)
;
|
(seit C++11)
(bis C++23) |
|
|
list
(
list
&&
other,
const
std::
type_identity_t
<
Allocator
>
&
alloc
)
;
|
(seit C++23)
(constexpr seit C++26) |
|
|
list
(
std::
initializer_list
<
T
>
init,
const Allocator & alloc = Allocator ( ) ) ; |
(11) |
(seit C++11)
(constexpr seit C++26) |
Konstruiert eine neue
list
aus verschiedenen Datenquellen, optional unter Verwendung einer benutzerdefinierten Allokator-Instanz
alloc
.
list
mit einem standardkonstruierten Allokator.
list
mit dem gegebenen Allokator
alloc
.
list
mit
count
standardmäßig eingefügten Objekten von
T
. Es werden keine Kopien erstellt.
list
mit
count
Kopien von Elementen mit dem Wert
value
.
|
Falls
|
(since C++11) |
list
mit den Inhalten des Bereichs
[
first
,
last
)
. Jeder Iterator in
[
first
,
last
)
wird genau einmal dereferenziert.
|
Falls
|
(bis C++11) |
|
Diese Überladung nimmt nur dann an der Überladungsauflösung teil, wenn
Falls
|
(seit C++11) |
list
mit den Inhalten des Bereichs
rg
. Jeder Iterator in
rg
wird genau einmal dereferenziert.
T
nicht
EmplaceConstructible
in
list
aus
*
ranges::
begin
(
rg
)
ist, ist das Verhalten undefiniert.
list
mit den Inhalten von
other
.
|
Der Allokator wird bezogen wie durch Aufruf von
std::
allocator_traits
<
Allocator
>
::
select_on_container_copy_construction
|
(seit C++11) |
list
mit den Inhalten von
other
. Der Allokator wird durch Move-Konstruktion von
other.
get_allocator
(
)
erhalten.
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 die Quelle des Bereichs 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 containerkompatibler Bereich |
Komplexität
Exceptions
Aufrufe von Allocator :: allocate können eine Exception werfen.
Hinweise
Nach Container-Verschiebekonstruktion (Überladung ( 8 ) ) 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 Erwägung gezogen.
| Feature-Test Makro | Wert | Std | Feature |
|---|---|---|---|
__cpp_lib_containers_ranges
|
202202L
|
(C++23) | Ranges-bewusste Konstruktion und Einfügung; Überladung ( 6 ) |
Beispiel
#include <iostream> #include <list> #include <string> template<typename T> std::ostream& operator<<(std::ostream& s, const std::list<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::list<std::string> words1{"the", "frogurt", "is", "also", "cursed"}; std::cout << "1: " << words1; // words2 == words1 std::list<std::string> words2(words1.begin(), words1.end()); std::cout << "2: " << words2; // words3 == words1 std::list<std::string> words3(words1); std::cout << "3: " << words3; // words4 ist {"Mo", "Mo", "Mo", "Mo", "Mo"} std::list<std::string> words4(5, "Mo"); std::cout << "4: " << words4; const auto rg = {"cat", "cow", "crow"}; #ifdef __cpp_lib_containers_ranges std::list<std::string> words5(std::from_range, rg); // Überladung (6) #else std::list<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 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 | als non-explicit festgelegt |
| 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 Werte dem Container zu
(öffentliche Elementfunktion) |
|
|
weist Werte dem Container zu
(öffentliche Elementfunktion) |