Share via


forward_list::merge

Combines two sorted sequences into a single sorted sequence in linear time. Removes the elements from the argument list, and inserts them into this forward_list. The two lists should be sorted by the same compare function object before the call to merge. The combined list will be sorted by that compare function object.

void merge(forward_list& _Right);
template<class Predicate>
    void merge(forward_list& _Right, Predicate _Comp);

Parameters

Parameter

Description

_Right

The forward list to merge from.

_Comp

The compare function object that is used to sort elements.

Remarks

forward_list::merge removes the elements from the forward_list_Right, and inserts them into this forward_list. Both sequences must be ordered by the same predicate, described below. The combined sequence is also ordered by that compare function object.

For the iterators Pi and Pj designating elements at positions i and j, the first member function imposes the order !(*Pj < *Pi) whenever i < j. (The elements are sorted in ascending order.) The second member function imposes the order !_Comp(*Pj, *Pi) whenever i < j.

No pairs of elements in the original controlled sequence are reversed in the resulting controlled sequence. If a pair of elements in the resulting controlled sequence compares equal (!(*Pi < *Pj) && !(*Pj < *Pi)), an element from the original controlled sequence appears before an element from the sequence controlled by _Right.

An exception occurs only if _Comp throws an exception. In that case, the controlled sequence is left in unspecified order and the exception is rethrown.

Requirements

Header: <forward_list>

Namespace: std

See Also

Reference

forward_list Class