cpp/algorithm/ranges/inplace merge

Merges two consecutive sorted ranges and  into one sorted range.

A sequence is said to be sorted with respect to the comparator and projection  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.

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).

@1@ Elements are compared using the given binary comparison function and projection object, and the ranges must be sorted with respect to the same.

@2@ Same as, but uses as the range, as if using  as , and  as.

Return value
An iterator equal to.

Complexity
Exactly comparisons, if additional memory buffer is available, where. Otherwise, comparisons. Additionally, twice as many projections as comparisons in both cases.

Possible implementation
This implementation only shows the slower algorithm used when no additional memory is available. See also the implementation in MSVC STL and libstdc++.