std::forward_list<T,Allocator>:: merge
|
void
merge
(
forward_list
&
other
)
;
|
(1) |
(C++11부터)
(C++26부터 constexpr) |
|
void
merge
(
forward_list
&&
other
)
;
|
(2) |
(C++11부터)
(C++26부터 constexpr) |
|
template
<
class
Compare
>
void merge ( forward_list & other, Compare comp ) ; |
(3) |
(C++11부터)
(C++26부터 constexpr) |
|
template
<
class
Compare
>
void merge ( forward_list && other, Compare comp ) ; |
(4) |
(C++11부터)
(C++26부터 constexpr) |
두 개의 정렬된 목록을 하나의 정렬된 목록으로 병합합니다.
- 만약 other 가 * this 와 동일한 객체를 참조하면, 아무 작업도 수행하지 않습니다.
- 그렇지 않으면, other 의 모든 요소를 * this 로 전송합니다. 병합 후 other 는 비어 있게 됩니다.
이 연산은 안정적입니다:
- 두 목록에서 동등한 요소들에 대해, * this 의 요소들은 항상 other 의 요소들보다 앞에 위치합니다.
- * this 와 other 의 동등한 요소들의 순서는 변경되지 않습니다.
- * this 또는 other 가 비교자 comp 에 대해 정렬되지 않은 경우 .
- get_allocator ( ) == other. get_allocator ( ) 가 false 인 경우.
어떤 반복자나 참조도 무효화되지 않습니다. * this 에서 이동된 요소들에 대한 포인터와 참조, 그리고 이 요소들을 참조하는 반복자들은 other 가 아닌 * this 의 동일한 요소들을 참조하게 됩니다.
목차매개변수
반환 값(없음) 예외어떤 이유로든 예외가 발생하면, 이러한 함수들은 아무런 효과를 가지지 않습니다 ( strong exception safety guarantee ). 단, 비교 연산에서 발생한 예외는 제외합니다. 복잡도만약 other 가 * this 와 동일한 객체를 참조하는 경우, 비교 연산이 수행되지 않습니다. 그렇지 않으면, N 1 을 std:: distance ( begin ( ) , end ( ) ) 로, N 2 을 std:: distance ( other. begin ( ) , other. end ( ) ) 로 설정합니다:
1,2)
최대
N
1
+N
2
-1
번의 비교를
operator
<
를 사용하여 수행합니다.
3,4)
최대
N
1
+N
2
-1
번의 비교 함수
comp
적용.
예제
이 코드 실행
#include <iostream> #include <forward_list> std::ostream& operator<<(std::ostream& ostr, const std::forward_list<int>& list) { for (const int i : list) ostr << ' ' << i; return ostr; } int main() { std::forward_list<int> list1 = {5, 9, 1, 3, 3}; std::forward_list<int> list2 = {8, 7, 2, 3, 4, 4}; list1.sort(); list2.sort(); std::cout << "list1: " << list1 << '\n'; std::cout << "list2: " << list2 << '\n'; list1.merge(list2); std::cout << "merged:" << list1 << '\n'; } 출력: list1: 1 3 3 5 9 list2: 2 3 4 4 7 8 merged: 1 2 3 3 3 4 4 5 7 8 9 결함 보고서다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
참조
| ||||||||||||||||||||||||||||||||||||