Namespaces
Variants

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

From cppreference.net
void splice_after ( const_iterator pos, forward_list & other ) ;
(1) (C++11부터)
(C++26부터 constexpr)
void splice_after ( const_iterator pos, forward_list && other ) ;
(2) (C++11부터)
(C++26부터 constexpr)
void splice_after ( const_iterator pos, forward_list & other,
const_iterator it ) ;
(3) (C++11부터)
(C++26부터 constexpr)
void splice_after ( const_iterator pos, forward_list && other,
const_iterator it ) ;
(4) (C++11부터)
(C++26부터 constexpr)
void splice_after ( const_iterator pos, forward_list & other,
const_iterator first, const_iterator last ) ;
(5) (C++11부터)
(C++26부터 constexpr)
void splice_after ( const_iterator pos, forward_list && other,
const_iterator first, const_iterator last ) ;
(6) (C++11부터)
(C++26부터 constexpr)

other 에서 * this 로 요소들을 전송합니다. 요소들은 pos 뒤에 삽입됩니다.

다음 조건 중 하나라도 충족되면, 동작은 정의되지 않습니다:

  • pos 가 범위 ( before_begin() , end() ) 내에 있지 않습니다.
  • get_allocator ( ) == other. get_allocator ( ) false 입니다.
1,2) other 의 모든 요소를 전송합니다. other 는 연산 후 비어 있는 상태가 됩니다.
만약 * this other 가 동일한 객체를 참조할 경우, 동작은 정의되지 않습니다.
3,4) 다음 요소를 전송합니다 it .
* this other 는 동일한 객체를 참조할 수 있습니다. 이 경우, pos == it 또는 pos == ++ it true 인 경우에는 아무런 효과가 없습니다.
만약 ++ it 가 범위 [ begin ( ) , end ( ) ) 내에 있지 않다면, 동작은 정의되지 않습니다.
5,6) ( first , last ) 범위 내의 요소들을 전송합니다.
* this other 는 동일한 객체를 참조할 수 있습니다.
다음 조건 중 하나라도 만족되면, 동작은 정의되지 않음:
  • ( first , last ) 유효한 범위 가 아닌 경우,
  • ( first , last ) 내의 임의의 iterator가 역참조 가능하지 않은 경우.
  • pos ( first , last ) 내에 있는 경우.

어떤 반복자나 참조도 무효화되지 않습니다. 만약 * this other 가 서로 다른 객체를 참조하는 경우, 전달된 요소들에 대한 반복자들은 이제 * this 를 가리키며, other 를 가리키지 않습니다.

목차

매개변수

pos - 콘텐츠가 삽입될 요소의 뒤 위치
other - 콘텐츠를 전송할 다른 컨테이너
it - other 에서 * this 로 전송할 요소의 이터레이터 바로 앞을 가리키는 이터레이터
first, last - other 에서 * this 로 전송할 요소들의 범위 를 정의하는 이터레이터 쌍

예외

1-4) 아무것도 throw하지 않습니다.

복잡도

1,2) other 의 크기에 선형적입니다.
3,4) 상수.
5,6) std:: distance ( first, last ) 에 대해 선형 시간 복잡도를 가집니다.

예제

#include <cassert>
#include <forward_list>
int main()
{
    using F = std::forward_list<int>;
    // 오버로드 (5)에서 열린 범위(first, last)의 의미를 보여줍니다:
    // l1의 첫 번째 요소는 전송되지 않습니다.
    F l1 = {1, 2, 3, 4, 5};
    F l2 = {10, 11, 12};
    l2.splice_after(l2.cbegin(), l1, l1.cbegin(), l1.cend());
    // l2.splice_after(l2.cbegin(), l1); 와 동등하지 않습니다
    // 이는 다음 코드와 동등합니다:
    // l2.splice_after(l2.cbegin(), l1, l1.cbefore_begin(), l1.end());
    assert((l1 == F{1}));
    assert((l2 == F{10, 2, 3, 4, 5, 11, 12}));
    // 오버로드 (1)
    F x = {1, 2, 3, 4, 5};
    F y = {10, 11, 12};
    x.splice_after(x.cbegin(), y);
    assert((x == F{1, 10, 11, 12, 2, 3, 4, 5}));
    assert((y == F{}));
    // 오버로드 (3)
    x = {1, 2, 3, 4, 5};
    y = {10, 11, 12};
    x.splice_after(x.cbegin(), y, y.cbegin());
    assert((x == F{1, 11, 2, 3, 4, 5}));
    assert((y == F{10, 12}));
    // 오버로드 (5)
    x = {1, 2, 3, 4, 5};
    y = {10, 11, 12};
    x.splice_after(x.cbegin(), y, y.cbegin(), y.cend());
    assert((x == F{1, 11, 12, 2, 3, 4, 5}));
    assert((y == F{10}));
}

결함 보고서

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

DR 적용 대상 게시된 동작 올바른 동작
LWG 2045 C++11 O(1) 스플라이싱이 보장될 수 없었음
get_allocator ( ) ! = other. get_allocator ( )
이 경우 동작은
정의되지 않음
LWG 2222 C++11 it 가 가리키는 요소는 전송되지 않지만, 이를 참조하는
포인터, 참조자 및 반복자는 스플라이싱 후 * this 의 요소를 참조함
계속 other 의 요소를
참조함

참고 항목

두 개의 정렬된 리스트를 병합합니다
(public member function)
특정 조건을 만족하는 요소들을 제거합니다
(public member function)
시작점 이전의 요소를 가리키는 반복자를 반환합니다
(public member function)