std::forward_list<T,Allocator>::merge (3) - Linux Manuals
std::forward_list<T,Allocator>::merge: std::forward_list<T,Allocator>::merge
NAME
std::forward_list<T,Allocator>::merge - std::forward_list<T,Allocator>::merge
Synopsis
void merge( forward_list& other ); (1) (since C++11)
void merge( forward_list&& other ); (1) (since C++11)
template <class Compare> (2) (since C++11)
void merge( forward_list& other, Compare comp );
template <class Compare> (2) (since C++11)
void merge( forward_list&& other, Compare comp );
Merges two sorted lists into one. The lists should be sorted into ascending order.
No elements are copied. The container other becomes empty after the operation. The function does nothing if other refers to the same object as *this. If get_allocator() != other.get_allocator(), the behavior is undefined. No iterators or references become invalidated, except that the iterators of moved elements now refer into *this, not into other. The first version uses operator< to compare the elements, the second version uses the given comparison function comp.
This operation is stable: for equivalent elements in the two lists, the elements from *this shall always precede the elements from other, and the order of equivalent elements of *this and other does not change.
Parameters
other - another container to merge
comp - While the signature does not need to have const &, the function must not modify the objects passed to it and must be able to accept all values of type (possibly const) Type1 and Type2 regardless of value_category (thus, Type1 & is not allowed
Return value
(none)
Exceptions
If an exception is thrown, this function has no effect (strong exception guarantee), except if the exception comes from the comparison function.
Complexity
at most std::distance(begin(), end()) + std::distance(other.begin(), other.end()) - 1 comparisons.
Example
// Run this code
Output:
See also
splice_after (public member function)