close
Namensräume
Varianten

std::list::splice

Aus cppreference.com

<metanoindex/>

 
 
 
std::list
Member-Funktionen
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
list::list
list::~list
list::operator=
list::assign
list::get_allocator
Elementzugriff zerstört
Original:
Element access
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
list::front
list::back
Iteratoren
Original:
Iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
list::begin
list::cbegin

(C++11)
list::end
list::cend

(C++11)
list::rbegin
list::crbegin

(C++11)
list::rend
list::crend

(C++11)
Kapazität
Original:
Capacity
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
list::empty
list::size
list::max_size
Modifiers
Original:
Modifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
list::clear
list::insert
list::emplace(C++11)
list::erase
list::push_front
list::emplace_front(C++11)
list::pop_front
list::push_back
list::emplace_back(C++11)
list::pop_back
list::resize
list::swap
Operations
Original:
Operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
list::merge
list::splice
list::remove
list::remove_if
list::reverse
list::unique
list::sort
 
<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

(None)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Komplexität

1-2)

Constant .
Original:
Constant.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

3)

Konstant, wenn this == &other, ansonsten linear in std::distance(first, last) .
Original:
Constant if this == &other, otherwise linear in std::distance(first, last).
The text has been machine-translated via Google Translate.
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) [edit]
entfernt Elemente anhand bestimmter Kriterien
(öffentliche Elementfunktion) [edit]