std::list::splice
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
<tbody> </tbody> void splice(const_iterator pos, list& other); |
(1) | |
void splice(const_iterator pos, list&& other); |
(1) | (seit C++11) |
void splice(const_iterator pos, list& other, const_iterator it); |
(2) | |
void splice(const_iterator pos, list&& other, const_iterator it); |
(2) | (seit C++11) |
void splice(const_iterator pos, list& other, const_iterator first, const_iterator last); |
(3) | |
void splice(const_iterator pos, list&& other, const_iterator first, const_iterator last); |
(3) | (seit C++11) |
Bewegt Elemente aus einer Liste in einer andere.
Dabei werden keine Elemente kopiert.
Das Verhalten ist, undefiniert, falls get_allocator() != other.get_allocator().
Während keine Iteratoren oder Referenzen ungültig werden, beziehen sich die Iteratoren der bewegten Elemente nun auf *this und nicht auf other.
1) Verschiebt alle Elemente aus other in *this. Die Elemente werden vor das Element, auf das pos zeigt, eingefügt. Der Behälter other ist leer nach dieser Operation. Falls this == &other, ist das Verhalten undefiniert.
2) Verschiebt das Element, auf das it zeigt, von other in *this. Das Element wird vor das Element, auf das pos zeigt, eingefügt.
3) Verschiebt die Elemente in dem Bereich [first, last) von other in *this. Die Elemente werden vor das Element, auf das pos zeigt, eingefügt. Das Verhalten ist undefiniert, falls pos ein Iterator im Bereich [first,last) ist .
Parameter
| pos | - | das Element, vor dem der Inhalt eingefügt wird |
| other | - | der Container, aus dem der Inhalt verschoben wird |
| it | - | das Element, das aus other in *this bewegt wird
|
| first, last | - | der Bereich von Elementen, der aus other in *this bewegt wird
|
Rückgabewert
You can help to correct and verify the translation. Click here for instructions.
Komplexität
1-2)
You can help to correct and verify the translation. Click here for instructions.
3)
this == &other, ansonsten linear in std::distance(first, last) .this == &other, otherwise linear in std::distance(first, last).You can help to correct and verify the translation. Click here for instructions.
Beispiel
#include <iostream>
#include <list>
std::ostream& operator<<(std::ostream& ostr, const std::list<int>& list)
{
for (auto &i : list) {
ostr << " " << i;
}
return ostr;
}
int main ()
{
std::list<int> list1 = { 1, 2, 3, 4, 5 };
std::list<int> list2 = { 10, 20, 30, 40, 50 };
auto it = list1.begin();
std::advance(it, 2);
list1.splice(it, list2);
std::cout << "list1: " << list1 << "\n";
std::cout << "list2: " << list2 << "\n";
list2.splice(list2.begin(), list1, it, list1.end());
std::cout << "list1: " << list1 << "\n";
std::cout << "list2: " << list2 << "\n";
}
Output:
list1: 1 2 10 20 30 40 50 3 4 5
list2:
list1: 1 2 10 20 30 40 50
list2: 3 4 5
Siehe auch
| vereinigt zwei sortierte Listen (öffentliche Elementfunktion) | |
| entfernt Elemente anhand bestimmter Kriterien (öffentliche Elementfunktion) | |