Merge Operations

In this lesson, we'll learn different ways of combining ranges.

Merge operations empower you to merge sorted ranges in a new sorted range. The algorithm requires that the ranges and the algorithm use the same sorting criterion. If not, the program is undefined. Per default the predefined sorting criterion std::less is used. If you use your sorting criterion, it has to obey the strict weak ordering. If not, the program is undefined.

You can merge two sorted ranges with std::inplace_merge and std::merge. You can check with std::includes if one sorted range is in another sorted range. You can merge with std::set_difference, std::set_intersection, std::set_symmetric_difference and std::set_union two sorted ranges in a new sorted range.

Merges in place two sorted sub ranges [first, mid) and [mid, last):

Get hands-on with 1200+ tech skills courses.