std::forward_list<T,Allocator>:: operator=
|
forward_list
&
operator
=
(
const
forward_list
&
other
)
;
|
(1) |
(seit C++11)
(constexpr seit C++26) |
| (2) | ||
|
forward_list
&
operator
=
(
forward_list
&&
other
)
;
|
(seit C++11)
(bis C++17) |
|
|
forward_list
&
operator
=
(
forward_list
&&
other
)
noexcept ( /* siehe unten */ ) ; |
(seit C++17)
(constexpr seit C++26) |
|
|
forward_list
&
operator
=
(
std::
initializer_list
<
value_type
>
ilist
)
;
|
(3) |
(seit C++11)
(constexpr seit C++26) |
Ersetzt den Inhalt des Containers.
Sei
traits
gleich
std::
allocator_traits
<
allocator_type
>
:
Inhaltsverzeichnis |
Parameter
| other | - | anderer Container, der als Datenquelle verwendet werden soll |
| ilist | - | Initialisierungsliste, die als Datenquelle verwendet werden soll |
Rückgabewert
* this
Komplexität
Exceptions
|
2)
noexcept
Spezifikation:
noexcept
(
std::
allocator_traits
<
Allocator
>
::
is_always_equal
::
value
)
|
(seit C++17) |
Hinweise
Nach Container-Verschiebungszuweisung (Überladung ( 2 ) ), sofern keine elementweise Verschiebungszuweisung durch inkompatible Allokatoren erzwungen wird, 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.
Beispiel
Der folgende Code verwendet den operator = , um eine std::forward_list einer anderen zuzuweisen:
#include <initializer_list> #include <iostream> #include <iterator> #include <forward_list> void print(const auto comment, const auto& container) { auto size = std::ranges::distance(container); std::cout << comment << "{ "; for (const auto& element : container) std::cout << element << (--size ? ", " : " "); std::cout << "}\n"; } int main() { std::forward_list<int> x{1, 2, 3}, y, z; const auto w = {4, 5, 6, 7}; std::cout << "Initially:\n"; print("x = ", x); print("y = ", y); print("z = ", z); std::cout << "Copy assignment copies data from x to y:\n"; y = x; print("x = ", x); print("y = ", y); std::cout << "Move assignment moves data from x to z, modifying both x and z:\n"; z = std::move(x); print("x = ", x); print("z = ", z); std::cout << "Assignment of initializer_list w to z:\n"; z = w; print("w = ", w); print("z = ", z); }
Ausgabe:
Initially:
x = { 1, 2, 3 }
y = { }
z = { }
Copy assignment copies data from x to y:
x = { 1, 2, 3 }
y = { 1, 2, 3 }
Move assignment moves data from x to z, modifying both x and z:
x = { }
z = { 1, 2, 3 }
Assignment of initializer_list w to z:
w = { 4, 5, 6, 7 }
z = { 4, 5, 6, 7 }
Siehe auch
konstruiert die
forward_list
(öffentliche Elementfunktion) |
|
|
weist Werte dem Container zu
(öffentliche Elementfunktion) |