list::list
Tworzy listę o określonym rozmiarze lub z elementami określonej wartości lub z określonych alokatora lub jako kopii całości lub części niektóre inne listy.
list( ); explicit list( const Allocator& Al ); explicit list( size_type Count ); list( size_type Count, const Type& Val ); list( size_type Count, const Type& Val, const Allocator& Al ); list( const list& Right ); list( list&& Right ); list( initializer_list<Type> IList, const Allocator& Al ); template<class InputIterator> list( InputIterator First, InputIterator Last ); template<class InputIterator > list( InputIterator First, InputIterator Last, const Allocator& Al );
Parametry
Parametr |
Opis |
Al |
Klasa alokatora do wykorzystania z tym obiektem. |
Count |
Liczba elementów na liście skonstruowany. |
Val |
Wartości elementów na liście. |
Right |
Lista zbudowany listy ma być kopię. |
First |
Pozycja pierwszego elementu w zakresie elementy do skopiowania. |
Last |
Pozycja pierwszego elementu poza zakres elementy do skopiowania. |
IList |
Initializer_list, zawierającego elementy do skopiowania. |
Uwagi
Wszystkie konstruktorów zapisania obiektu alokatora (Al) i zainicjować listy.
get_allocator zwraca kopię obiektu alokatora użyta do skonstruowania listy.
Pierwsze dwa konstruktory Określ pusta lista początkowa, druga określającą typ alokatora (Al) do użycia.
Konstruktor trzeci określa powtórzenia określonej liczby (Count) elementów wartości domyślnej dla klasy typu.
Konstruktory czwartym i piątym Określ powtórzenia (Count) elementy wartości Val.
Konstruktor szóstego Określa kopię listy Right.
Konstruktor siódmego przesuwa listy Right.
Konstruktor ósmej użyto initializer_list do określenia elementów.
Kolejne dwa konstruktory skopiuj zakres [First, Last) z listy.
Żaden z konstruktorów wykonać wszelkie przeniesieniom tymczasowe.
Przykład
// list_class_list.cpp
// compile with: /EHsc
#include <list>
#include <iostream>
int main()
{
using namespace std;
// Create an empty list c0
list <int> c0;
// Create a list c1 with 3 elements of default value 0
list <int> c1(3);
// Create a list c2 with 5 elements of value 2
list <int> c2(5, 2);
// Create a list c3 with 3 elements of value 1 and with the
// allocator of list c2
list <int> c3(3, 1, c2.get_allocator());
// Create a copy, list c4, of list c2
list <int> c4(c2);
// Create a list c5 by copying the range c4[_First, _Last)
list <int>::iterator c4_Iter = c4.begin();
c4_Iter++;
c4_Iter++;
list <int> c5(c4.begin(), c4_Iter);
// Create a list c6 by copying the range c4[_First, _Last) and with
// the allocator of list c2
c4_Iter = c4.begin();
c4_Iter++;
c4_Iter++;
c4_Iter++;
list <int> c6(c4.begin(), c4_Iter, c2.get_allocator());
cout << "c1 =";
for (auto c : c1)
cout << " " << c;
cout << endl;
cout << "c2 =";
for (auto c : c2)
cout << " " << c;
cout << endl;
cout << "c3 =";
for (auto c : c3)
cout << " " << c;
cout << endl;
cout << "c4 =";
for (auto c : c4)
cout << " " << c;
cout << endl;
cout << "c5 =";
for (auto c : c5)
cout << " " << c;
cout << endl;
cout << "c6 =";
for (auto c : c6)
cout << " " << c;
cout << endl;
// Move list c6 to list c7
list <int> c7(move(c6));
cout << "c7 =";
for (auto c : c7)
cout << " " << c;
cout << endl;
// Construct with initializer_list
list<int> c8({ 1, 2, 3, 4 });
cout << "c8 =";
for (auto c : c8)
cout << " " << c;
cout << endl;
}
Wymagania
Nagłówek: < listy >
Przestrzeń nazw: std