Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Standard C++ Library Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

14.5 Merge Ordered Sequences

The algorithm std::merge() combines two ordered sequences to form a new ordered sequence. The size of the result is the sum of the sizes of the two argument sequences. This should be contrasted with the std::set_union() operation, which eliminates elements that are duplicated in both sets. The std::set_union() function is described later in this chapter.

The merge operation is stable. This means, for equal elements in the two ranges, not only is the relative ordering of values from each range preserved, but the values from the first range always precede the elements from the second. The two ranges are described by a pair of iterators, whereas the result is defined by a single output iterator. The arguments are shown in the following declaration:

The example program illustrates a simple merge, the use of a merge with an inserter, and the use of a merge with an output stream iterator.

The algorithm std::inplace_merge() (Section 12.4.6, "Merge Two Adjacent Sequences into One,") can be used to merge two sections of a single sequence into one sequence.



Previous fileTop of DocumentContentsIndex pageNext file

Copyright (c) 1994-2006 Rogue Wave Software, a Quovadx Division.
Licensed under the Apache License, Version 2.0.
Contact Rogue Wave about documentation or support issues. You can also seek help from other developers through the Apache stdcxx community (see below).

For more information on the Rogue Wave Standard C++ Library under open source, see Section 1.2.