Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

set_union()

Library:  Algorithms


Function

Local Index

No Entries

Summary

A basic set operation (algorithm) for constructing a sorted union

Synopsis

#include <algorithm>

namespace std {
  template <class InputIterator1, class InputIterator2,
            class OutputIterator>
  OutputIterator
  set_union(InputIterator1 start1, InputIterator1 finish1,
            InputIterator2 start2, InputIterator2 finish2,
            OutputIterator result);

  template <class InputIterator1, class InputIterator2,
            class OutputIterator, class Compare>
  OutputIterator
  set_union(InputIterator1 start1, InputIterator1 finish1,
            InputIterator2 start2, InputIterator2 finish2,
            OutputIterator result, Compare comp);
}

Description

The set_union() algorithm constructs a sorted union of the elements from the two ranges. It returns the end of the constructed range. set_union() is stable, which means that if an element is present in both ranges, the one from the first range is copied. The result of set_union() is undefined if the result range overlaps with either of the original ranges. Note that set_union() does not merge the two sorted sequences. If an element is present in both sequences, only the element from the first sequence is copied to result. (Use the merge() algorithm to create an ordered merge of two sorted sequences that contains all the elements from both sequences.)

set_union() assumes that the sequences are sorted using operator<(), unless an alternative comparison function object (comp) is provided.

Complexity

At most ((finish1 - start1) + (finish2 - start2)) * 2 -1 comparisons are performed.

Example

See Also

includes(), Iterators, set_intersection(), set_difference(), set_symmetric_difference()

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 25.3.5.2



Previous fileTop of DocumentContentsIndex pageNext file