list::list
特定のサイズ、特定の値の要素、または特定のアロケーターを持つリストを構築します。あるいは他のリストの全体または一部のコピーとして構築します。
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 );
パラメーター
パラメーター |
説明 |
Al |
このオブジェクトに対して使用するアロケーター クラス。 |
Count |
構築されたリスト内の要素の数。 |
Val |
リスト内の要素の値。 |
Right |
構築されたリストがコピーになる元のリスト。 |
First |
コピーする要素範囲内の最初の要素の位置。 |
Last |
コピーする要素範囲を超える最初の要素の位置。 |
IList |
コピーされる要素を含む initializer_list。 |
解説
すべてのコンストラクターが、アロケーター オブジェクト (Al) を格納し、リストを初期化します。
get_allocator は、リストの構築に使用されるアロケーター オブジェクトのコピーを返します。
最初の 2 つのコンストラクターは、空の初期リストを指定し、2 番目のコンストラクターは、使用するアロケーターの型 (Al) を指定します。
3 番目のコンストラクターは、Type クラスの、指定された数 (Count) の既定値の要素を繰り返すことを指定します。
4 番目と 5 番目のコンストラクターは、値 Count の Val 個の要素を繰り返すことを指定します。
6 番目のコンストラクターは、リスト Right のコピーを指定します。
7 番目のコンストラクターは、リスト Right を移動します。
8 番目のコンストラクターは、initializer_list を使用して要素を指定します。
次の 2 つのコンストラクターは、リストの範囲 [First, Last) をコピーします。
コンストラクターでは、暫定的な再割り当てを実行しません。
使用例
// 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;
}
必要条件
ヘッダー: <list>
名前空間: std