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.6 set Operations

The operations of set_union, set_intersection, and set_difference were all described in Section 9.2.7, "set Operations," when we discussed the set container class. However, the algorithms that implement these operations are generic, and applicable to any ordered data structure. The algorithms assume the input ranges are ordered collections that represent multisets; that is, elements can be repeated. However, if the inputs represent sets, then the result will always be a set. Unlike the std::merge() algorithm, none of the set algorithms produce repeated elements in the output that are not present in the input sets.

The set operations all have the same format. The two input sets are specified by pairs of input iterators. The output set is specified by an input iterator, and the end of this range is returned as the result value. An optional comparison operator is the final argument. In all cases it is required that the output sequence not overlap in any manner with either of the input sequences.

The example program illustrates the use of the four set algorithms, std::set_union(), std::set_intersection(), std::set_difference(), and std::set_symmetric_difference(). It also shows a call on std::merge() in order to contrast the merge and the set union operations. The algorithm std::includes() is slightly different. Again the two input sets are specified by pairs of input iterators, and the comparison operator is an optional fifth argument. The return value for the algorithm is true if the first set is entirely included in the second, and false otherwise.



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.