Namespaces
Variants

std::vector<T,Allocator>:: append_range

From cppreference.net

template < container-compatible-range < T > R >
constexpr void append_range ( R && rg ) ;
(C++23 이후)

rg 범위의 요소들을 역순 없이 end() 앞에 복사본을 삽입합니다.

만약 연산 후 새로운 size() 가 기존 capacity() 보다 크면 재할당이 발생하며, 이 경우 모든 반복자(including the end() iterator)와 모든 요소에 대한 참조가 무효화됩니다. 그렇지 않으면 end() 반복자만 무효화됩니다.

rg 내의 각 iterator는 정확히 한 번 역참조됩니다.

목차

매개변수

rg - a container compatible range , that is, an input_range whose elements are convertible to T
Type requirements
-
If any of the following conditions is satisfied, the behavior is undefined:

복잡도

재할당이 발생하는 경우, 결과 vector 의 요소 수에 대해 선형 시간이 소요됩니다; 그렇지 않은 경우, 삽입된 요소 수와 end() 까지의 거리의 합에 대해 선형 시간이 소요됩니다.

다음 조건 중 하나가 만족되면, 최대 한 번의 재할당을 수행합니다:

(C++26부터)

예외

복사 생성자, 이동 생성자, 할당 연산자, 이동 할당 연산자 이외의 이유로 예외가 발생한 경우, T 의 복사 생성자, 이동 생성자, 할당 연산자, 이동 할당 연산자 또는 InputIterator 연산에 의해 예외가 발생하지 않은 경우에는 아무런 영향이 없습니다. 끝에 단일 요소를 삽입하는 동안 예외가 발생하고 T CopyInsertable 이거나 std::is_nothrow_move_constructible_v <T> true 인 경우에는 아무런 영향이 없습니다. 그렇지 않고, CopyInsertable 이 아닌 T 의 이동 생성자에 의해 예외가 발생한 경우, 그 영향은 명시되지 않습니다.

참고 사항

기능 테스트 매크로 표준 기능
__cpp_lib_containers_ranges 202202L (C++23) Ranges-aware 생성 및 삽입

예제

#include <cassert>
#include <vector>
#include <list>
int main()
{
    auto head = std::vector{1, 2, 3, 4};
    const auto tail = std::list{-5, -6, -7};
#ifdef __cpp_lib_containers_ranges
    head.append_range(tail);
#else
    head.insert(head.end(), tail.cbegin(), tail.cend());
#endif
    assert((head == std::vector{1, 2, 3, 4, -5, -6, -7}));
}

참고 항목

요소들의 범위를 삽입합니다
(public member function)
끝에 요소를 추가합니다
(public member function)
끝에 제자리에서 요소를 생성합니다
(public member function)