다음을 통해 공유


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는 목록을 생성하는 데 사용되는 할당자 개체의 복사본을 반환합니다.

처음 두 생성자는 빈 초기 목록을 지정하며, 그 중 두 번째 생성자는 사용할 할당자 형식(Al)을 지정합니다.

세 번째 생성자는 Type 클래스에 대한 기본값의 요소에 대해 지정된 수(Count)의 반복을 지정합니다.

네 번째와 다섯 번째 생성자는 Val 값의 요소 반복(Count)을 지정합니다.

여섯 번째 생성자는 Right 목록의 복사본을 지정합니다.

일곱 번째 생성자는 Right 목록을 이동합니다.

여덟 번째 생성자는 initializer_list를 사용하여 요소를 지정합니다.

그 다음 두 생성자는 목록의 [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

참고 항목

참조

list 클래스

표준 템플릿 라이브러리