Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext
merge
Prototype

template<
    class SinglePassRange1,
    class SinglePassRange2,
    class OutputIterator
    >
OutputIterator merge(const SinglePassRange1& rng1,
                     const SinglePassRange2& rng2,
                     OutputIterator          out);

template<
    class SinglePassRange1,
    class SinglePassRange2,
    class OutputIterator,
    class BinaryPredicate
    >
OutputIterator merge(const SinglePassRange1& rng1,
                     const SinglePassRange2& rng2,
                     OutputIterator          out,
                     BinaryPredicate         pred);

Description

merge combines two sorted ranges rng1 and rng2 into a single sorted range by copying elements. merge is stable. The return value is out + distance(rng1) + distance(rng2).

The two versions of merge differ by how they compare the elements.

The non-predicate version uses the operator<() for the range value type. The predicate version uses the predicate instead of operator<().

Definition

Defined in the header file boost/range/algorithm/merge.hpp

Requirements

For the non-predicate version:

For the predicate version:

Precondition:
For the non-predicate version:
For the predicate version:
Complexity

Linear. There are no comparisons if both rng1 and rng2 are empty, otherwise at most distance(rng1) + distance(rng2) - 1 comparisons.


PrevUpHomeNext