cpp/algorithm/merge

Merges two sorted ranges and  into one sorted range beginning at.

A sequence is said to be sorted with respect to a comparator if for any iterator  pointing to the sequence and any non-negative integer  such that  is a valid iterator pointing to an element of the sequence,  evaluates to.

@1@ Elements are compared using. @3@ Elements are compared using the given binary comparison function. @2,4@ Same as, but executed according to.

This merge function is stable, which means that for equivalent elements in the original two ranges, the elements from the first range (preserving their original order) precede the elements from the second range (preserving their original order).

The behavior is undefined if the destination range overlaps either of the input ranges (the input ranges may overlap each other).

Return value
An output iterator to element past the last element copied.

Complexity
Given as : @1@ at most comparisons using @2@ comparisons using @3@ at most comparisons using @4@ comparisons using

Possible implementation
See also the implementations in libstdc++ and libc++.