Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

set_difference


Algorithm

Summary

A basic set operation for constructing a sorted difference.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

None

Synopsis

#include <algorithm>
template <class InputIterator1, class InputIterator2,
          class OutputIterator>
  OutputIterator 
     set_difference (InputIterator1 first1, 
                     InputIterator1 last1,
                     InputIterator2 first2, 
                     InputIterator2 last2,
                     OutputIterator result);
template <class InputIterator1, class InputIterator2,
          class OutputIterator, class Compare>
  OutputIterator 
     set_difference (InputIterator1 first1, 
                     InputIterator1 last1,
                     InputIterator2 first2, 
                     InputIterator2 last2,
                     OutputIterator result, Compare comp);

Description

The set_difference algorithm constructs a sorted difference that includes copies of the elements that are present in the range [first1, last1) but are not present in the range [first2, last2). It returns the end of the constructed range.

As an example, assume we have the following two sets:

1 2 3 4 5

and

3 4 5 6 7

The result of applying set_difference is the set:

1 2

The result of set_difference is undefined if the result range overlaps with either of the original ranges.

set_difference assumes that the ranges are sorted using the default comparison operator less than (<), unless an alternative comparison operator (comp) is provided.

Use the set_symetric_difference algorithm to return a result that contains all elements that are not in common between the two sets.

Complexity

At most ((last1 - first1) + (last2 - first2)) * 2 -1 comparisons are performed.

Example

Program Output

Warnings

If your compiler does not support default template parameters, then you always need to supply the Compare template argument and the Allocator template argument. For instance, you need to write:

set<int, less<int> allocator<int> >

instead of:

set<int>

If your compiler does not support namespaces, then you do not need the using declaration for std.

See Also

includes, set, set_union,set_intersection, set_symmetric_difference



Previous fileTop of documentContentsIndexNext file
Copyright (c) 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998