Udostępnij za pośrednictwem


list::splice

Usuwa elementy z listy źródłowej i wstawianie ich do listy lokalizacji docelowej.

// insert the entire source list void splice( const_iterator Where, list<Type, Allocator>& Source ); void splice( const_iterator Where, list<Type, Allocator>&& Source );  // insert one element of the source list void splice( const_iterator Where, list<Type, Allocator>& Source, const_iterator Iter ); void splice( const_iterator Where, list<Type, Allocator>&& Source, const_iterator Iter );  // insert a range of elements from the source list void splice( const_iterator Where, list<Type, Allocator>& Source, const_iterator First, const_iterator Last );  void splice( const_iterator Where, list<Type, Allocator>&& Source, const_iterator First, const_iterator Last );

Parametry

  • Where
    Pozycja na liście lokalizacji docelowej, przed którym ma zostać wstawiony.

  • Source
    Lista źródeł, który ma zostać umieszczone na liście lokalizacji docelowej.

  • Iter
    Element, który ma zostać wstawiony z listy źródeł.

  • First
    Pierwszym elementem w zakresie, który ma zostać wstawiony z listy źródeł.

  • Last
    Pozycja pierwszego po ostatnim elemencie zakresu, który ma zostać wstawiony z listy źródeł.

Uwagi

Pierwszy para funkcji elementów członkowskich wstawia wszystkie elementy na liście źródło listę lokalizacji docelowej przed pozycją odwołuje się Where i usuwa wszystkie elementy z listy źródłowej.(&Sourcenie musi być równa this.)

Druga para funkcji elementów członkowskich wstawia element odwołuje się Iter przed pozycję na liście docelowy odwołuje się Where i usuwa Iter z listy źródeł.(Jeśli Where == Iter || Where == ++Iter, Brak zmian symboli.)

Trzeci para funkcji elementów członkowskich Wstawia zakres ustaleniami [First, Last) przed elementu na liście docelowej odwołuje się Where i usuwa ten zakres elementy z listy źródłowej.(Jeśli &Source == this, zakres [First, Last) nie może zawierać elementu wskazywanego przez Where.)

Jeśli wstawia ranged splice N elementów, a &Source != this, obiekt klasy sterująca jest zwiększany N razy.

W każdym przypadku Iteratory, wskaźniki lub odwołania, które odwołują się do elementów spliced ważność i są przekazywane do kontenera docelowego.

Przykład

// list_splice.cpp
// compile with: /EHsc /W4
#include <list>
#include <iostream>

using namespace std;

template <typename S> void print(const S& s) {
    cout << s.size() << " elements: ";

    for (const auto& p : s) {
        cout << "(" << p << ") ";
    }

    cout << endl;
}

int main()
{
    list<int> c1{10,11};
    list<int> c2{20,21,22};
    list<int> c3{30,31};
    list<int> c4{40,41,42,43};

    list<int>::iterator where_iter;
    list<int>::iterator first_iter;
    list<int>::iterator last_iter;

    cout << "Beginning state of lists:" << endl;
    cout << "c1 = ";
    print(c1);
    cout << "c2 = ";
    print(c2);
    cout << "c3 = ";
    print(c3);
    cout << "c4 = ";
    print(c4);

    where_iter = c2.begin();
    ++where_iter; // start at second element
    c2.splice(where_iter, c1);
    cout << "After splicing c1 into c2:" << endl;
    cout << "c1 = ";
    print(c1);
    cout << "c2 = ";
    print(c2);

    first_iter = c3.begin();
    c2.splice(where_iter, c3, first_iter);
    cout << "After splicing the first element of c3 into c2:" << endl;
    cout << "c3 = ";
    print(c3);
    cout << "c2 = ";
    print(c2);

    first_iter = c4.begin();
    last_iter = c4.end();
    // set up to get the middle elements
    ++first_iter;
    --last_iter;
    c2.splice(where_iter, c4, first_iter, last_iter);
    cout << "After splicing a range of c4 into c2:" << endl;
    cout << "c4 = ";
    print(c4);
    cout << "c2 = ";
    print(c2);
}
  

Wymagania

Nagłówek: < listy >

Przestrzeń nazw: std

Zobacz też

Informacje

list — Klasa

Standardowa biblioteka szablonów