Namespaces
Variants

std::forward_list<T,Allocator>:: forward_list

From cppreference.net
forward_list ( ) : forward_list ( Allocator ( ) ) { }
(1) (C++26부터 constexpr)
explicit forward_list ( const Allocator & alloc ) ;
(2) (C++26부터 constexpr)
explicit forward_list ( size_type count,
const Allocator & alloc = Allocator ( ) ) ;
(3) (C++26부터 constexpr)
forward_list ( size_type count, const T & value,
const Allocator & alloc = Allocator ( ) ) ;
(4) (C++26부터 constexpr)
template < class InputIt >

forward_list ( InputIt first, InputIt last,

const Allocator & alloc = Allocator ( ) ) ;
(5) (C++26부터 constexpr)
template < container-compatible-range < T > R >

forward_list ( std:: from_range_t , R && rg,

const Allocator & alloc = Allocator ( ) ) ;
(6) (C++23부터)
(C++26부터 constexpr)
forward_list ( const forward_list & other ) ;
(7) (C++26부터 constexpr)
forward_list ( forward_list && other ) ;
(8) (C++26부터 constexpr)
(9)
forward_list ( const forward_list & other, const Allocator & alloc ) ;
(C++23 이전)
forward_list ( const forward_list & other,
const std:: type_identity_t < Allocator > & alloc ) ;
(C++23 이후)
(C++26 이후 constexpr)
(10)
forward_list ( forward_list && other, const Allocator & alloc ) ;
(C++23 이전)
forward_list ( forward_list && other,
const std:: type_identity_t < Allocator > & alloc ) ;
(C++23 이후)
(C++26 이후 constexpr)
forward_list ( std:: initializer_list < T > init,
const Allocator & alloc = Allocator ( ) ) ;
(11) (C++26부터 constexpr)

다양한 데이터 소스로부터 새로운 forward_list 를 구성하며, 선택적으로 사용자 제공 할당자 alloc 를 사용합니다.

1) 기본 생성자. 기본 생성된 할당자로 빈 forward_list 를 생성합니다.
만약 Allocator DefaultConstructible 가 아닐 경우, 동작은 정의되지 않습니다.
2) 주어진 할당자 alloc 를 사용하여 빈 forward_list 를 생성합니다.
3) forward_list count 개의 기본 생성된 T 객체로 생성합니다. 복사는 발생하지 않습니다.
만약 T DefaultInsertable forward_list 에 삽입 가능하지 않다면, 동작은 정의되지 않습니다.
4) forward_list count 개의 value 값으로 생성합니다.
만약 T CopyInsertable forward_list 에 대해 아니라면, 동작은 정의되지 않습니다.
5) 범위 [ first , last ) 의 내용으로 forward_list 를 생성합니다. [ first , last ) 범위 내의 각 반복자는 정확히 한 번 역참조됩니다.
이 오버로드는 InputIt LegacyInputIterator 요구 사항을 충족할 경우에만 오버로드 해결에 참여합니다.
만약 T EmplaceConstructible 가 아니라면 forward_list * first 로부터, 동작은 정의되지 않습니다.
6) 범위 rg 의 내용으로 forward_list 를 생성합니다. rg 내의 각 반복자는 정확히 한 번 역참조됩니다.
만약 T EmplaceConstructible 가 아닌 경우 forward_list * ranges:: begin ( rg ) 로부터 생성될 수 없다면, 동작은 정의되지 않습니다.
7) 복사 생성자. forward_list other 의 내용으로 생성합니다. 할당자는 std:: allocator_traits < Allocator > :: select_on_container_copy_construction
( other. get_allocator ( ) )
를 호출하여 얻습니다.
8) 이동 생성자. forward_list other 의 내용으로 생성합니다. 할당자는 other. get_allocator ( ) 로부터 이동 생성으로 얻습니다.
9) 복사 생성자와 동일하지만, alloc 이 할당자로 사용된다는 점이 다릅니다.
만약 T CopyInsertable forward_list 에 대해 아니라면, 동작은 정의되지 않습니다.
10) 이동 생성자와 동일하지만, alloc 가 할당자로 사용된다는 점이 다릅니다.
만약 T MoveInsertable forward_list 에 대해 아니라면, 동작은 정의되지 않습니다.
11) 다음에 해당함: forward_list ( il. begin ( ) , il. end ( ) , alloc ) .

목차

매개변수

alloc - 이 컨테이너의 모든 메모리 할당에 사용할 할당자
count - 컨테이너의 크기
value - 컨테이너 요소를 초기화할 값
first, last - 복사할 요소들의 소스 범위 를 정의하는 반복자 쌍
other - 컨테이너 요소를 초기화하는 데 사용할 소스로 사용할 다른 컨테이너
init - 컨테이너 요소를 초기화할 초기화자 리스트
rg - 컨테이너 호환 범위

복잡도

1,2) 상수.
3,4) count 에 대해 선형적입니다.
5) 선형 시간 복잡도 std:: distance ( first, last ) .
6) 선형 시간 복잡도, ranges:: distance ( rg ) .
7) other. size ( ) 에 선형적입니다.
8) 상수.
9) other. size ( ) 에 선형적입니다.
10) other. size ( ) 에 대해 선형 시간, alloc ! = other. get_allocator ( ) 인 경우, 그렇지 않으면 상수 시간.
11) 선형적으로 init. size ( ) .

예외

Allocator :: allocate 호출은 예외를 던질 수 있습니다.

참고 사항

컨테이너 이동 생성 후 (오버로드 ( 8 ) ), other 에 대한 참조, 포인터 및 반복자(끝 반복자 제외)는 유효하게 유지되지만, 이제는 * this 에 있는 요소들을 참조합니다. 현재 표준은 [container.reqmts]/67 의 포괄적 명시를 통해 이 보장을 제공하며, LWG issue 2321 를 통해 더 직접적인 보장이 검토 중에 있습니다.

기능 테스트 매크로 표준 기능
__cpp_lib_containers_ranges 202202L (C++23) 범위 인식 생성 및 삽입; 오버로드 ( 6 )

예제

#include <forward_list>
#include <iostream>
#include <string>
template<typename T>
std::ostream& operator<<(std::ostream& s, const std::forward_list<T>& v)
{
    s.put('{');
    for (char comma[]{'\0', ' ', '\0'}; const auto& e : v)
        s << comma << e, comma[0] = ',';
    return s << "}\n";
}
int main()
{
    // C++11 초기화 리스트 구문:
    std::forward_list<std::string> words1{"the", "frogurt", "is", "also", "cursed"};
    std::cout << "1: " << words1;
    // words2 == words1
    std::forward_list<std::string> words2(words1.begin(), words1.end());
    std::cout << "2: " << words2;
    // words3 == words1
    std::forward_list<std::string> words3(words1);
    std::cout << "3: " << words3;
    // words4는 {"Mo", "Mo", "Mo", "Mo", "Mo"}
    std::forward_list<std::string> words4(5, "Mo");
    std::cout << "4: " << words4;
    const auto rg = {"cat", "cow", "crow"};
#ifdef __cpp_lib_containers_ranges
    std::forward_list<std::string> words5(std::from_range, rg); // 오버로드 (6)
#else
    std::forward_list<std::string> words5(rg.begin(), rg.end()); // 오버로드 (5)
#endif
    std::cout << "5: " << words5;
}

출력:

1: {the, frogurt, is, also, cursed}
2: {the, frogurt, is, also, cursed}
3: {the, frogurt, is, also, cursed}
4: {Mo, Mo, Mo, Mo, Mo}
5: {cat, cow, crow}

결함 보고서

다음 동작 변경 결함 보고서는 이전에 게시된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 2193 C++11 기본 생성자가 explicit였음 non-explicit로 변경
LWG 2210 C++11 오버로드 ( 3 ) 에 할당자 매개변수가 없었음 매개변수 추가
N3346 C++11 오버로드 ( 3 ) 에서 컨테이너 내 요소들이
value-initialized되었음
default-inserted로 변경

참고 항목

컨테이너에 값을 할당합니다
(public member function)
컨테이너에 값을 할당합니다
(public member function)