std::forward_list<T,Allocator>:: forward_list
|
forward_list
(
)
:
forward_list
(
Allocator
(
)
)
{
}
|
(1) | (constexpr seit C++26) |
|
explicit
forward_list
(
const
Allocator
&
alloc
)
;
|
(2) | (constexpr seit C++26) |
|
explicit
forward_list
(
size_type count,
const Allocator & alloc = Allocator ( ) ) ; |
(3) | (constexpr seit C++26) |
|
forward_list
(
size_type count,
const
T
&
value,
const Allocator & alloc = Allocator ( ) ) ; |
(4) | (constexpr seit C++26) |
|
template
<
class
InputIt
>
forward_list
(
InputIt first, InputIt last,
|
(5) | (constexpr seit C++26) |
|
template
<
container-compatible-range
<
T
>
R
>
forward_list
(
std::
from_range_t
, R
&&
rg,
|
(6) |
(seit C++23)
(constexpr seit C++26) |
|
forward_list
(
const
forward_list
&
other
)
;
|
(7) | (constexpr seit C++26) |
|
forward_list
(
forward_list
&&
other
)
;
|
(8) | (constexpr seit C++26) |
| (9) | ||
|
forward_list
(
const
forward_list
&
other,
const
Allocator
&
alloc
)
;
|
(bis C++23) | |
|
forward_list
(
const
forward_list
&
other,
const std:: type_identity_t < Allocator > & alloc ) ; |
(seit C++23)
(constexpr seit C++26) |
|
| (10) | ||
|
forward_list
(
forward_list
&&
other,
const
Allocator
&
alloc
)
;
|
(bis C++23) | |
|
forward_list
(
forward_list
&&
other,
const std:: type_identity_t < Allocator > & alloc ) ; |
(seit C++23)
(constexpr seit C++26) |
|
|
forward_list
(
std::
initializer_list
<
T
>
init,
const Allocator & alloc = Allocator ( ) ) ; |
(11) | (constexpr seit C++26) |
Konstruiert eine neue
forward_list
aus verschiedenen Datenquellen, optional unter Verwendung einer benutzerdefinierten Zuweisung
alloc
.
forward_list
mit einem standardkonstruierten Allokator.
forward_list
mit dem gegebenen Allokator
alloc
.
forward_list
mit
count
standardmäßig eingefügten Objekten von
T
. Es werden keine Kopien erstellt.
forward_list
mit
count
Kopien der Elemente mit dem Wert
value
.
forward_list
mit den Inhalten des Bereichs
[
first
,
last
)
. Jeder Iterator in
[
first
,
last
)
wird genau einmal dereferenziert.
InputIt
die Anforderungen von
LegacyInputIterator
erfüllt.
forward_list
mit den Inhalten des Bereichs
rg
. Jeder Iterator in
rg
wird genau einmal dereferenziert.
T
nicht
EmplaceConstructible
in
forward_list
von
*
ranges::
begin
(
rg
)
ist, ist das Verhalten undefiniert.
forward_list
mit den Inhalten von
other
. Der Allokator wird erhalten, als ob durch Aufruf von
std::
allocator_traits
<
Allocator
>
::
select_on_container_copy_construction
( other. get_allocator ( ) ) .
forward_list
mit den Inhalten von
other
. Der Allokator wird durch Move-Konstruktion von
other.
get_allocator
(
)
erhalten.
InhaltParameter
Komplexität
1,2)
Konstant.
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
(
)
.
AusnahmenAufrufe von Allocator :: allocate können eine Exception werfen. AnmerkungenNach der Container-Verschiebekonstruktion (Überladung (8)), bleiben Referenzen, Zeiger und Iteratoren, die ursprünglich auf Elemente in
Beispiel
Diesen Code ausführen
#include <forward_list> #include <iostream> #include <string> template<typename T> std::ostream& operator<<(std::ostream& s, const std::forward_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::forward_list<std::string> words1{"the", "frogurt", "is", "also", "cursed"}; std::cout << "1: " << words1; // words2 == words1 std::forward_list<std::string> words2(words1.begin(), words1.end()); std::cout << "2: " << words2; // words3 == words1 std::forward_list<std::string> words3(words1); std::cout << "3: " << words3; // words4 ist {"Mo", "Mo", "Mo", "Mo", "Mo"} std::forward_list<std::string> words4(5, "Mo"); std::cout << "4: " << words4; const auto rg = {"cat", "cow", "crow"}; #ifdef __cpp_lib_containers_ranges std::forward_list<std::string> words5(std::from_range, rg); // Überladung (6) #else std::forward_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}
FehlerberichteDie folgenden verhaltensändernden Fehlerberichte wurden rückwirkend auf zuvor veröffentlichte C++-Standards angewendet.
Siehe auch
|