thrust

◆ set_difference() [4/4]

template<typename InputIterator1 , typename InputIterator2 , typename OutputIterator , typename StrictWeakCompare >
OutputIterator thrust::set_difference ( InputIterator1  first1,
InputIterator1  last1,
InputIterator2  first2,
InputIterator2  last2,
OutputIterator  result,
StrictWeakCompare  comp 
)

set_difference constructs a sorted range that is the set difference of the sorted ranges [first1, last1) and [first2, last2). The return value is the end of the output range.

In the simplest case, set_difference performs the "difference" operation from set theory: the output range contains a copy of every element that is contained in [first1, last1) and not contained in [first2, last1). The general case is more complicated, because the input ranges may contain duplicate elements. The generalization is that if [first1, last1) contains m elements that are equivalent to each other and if [first2, last2) contains n elements that are equivalent to them, the last max(m-n,0) elements from [first1, last1) range shall be copied to the output range.

This version of set_difference compares elements using a function object comp.

Parameters
first1The beginning of the first input range.
last1The end of the first input range.
first2The beginning of the second input range.
last2The end of the second input range.
resultThe beginning of the output range.
compComparison operator.
Returns
The end of the output range.
Template Parameters
InputIterator1is a model of Input Iterator, InputIterator1's value_type is convertable to StrictWeakCompare's first_argument_type. and InputIterator1's value_type is convertable to a type in OutputIterator's set of value_types.
InputIterator2is a model of Input Iterator, InputIterator2's value_type is convertable to StrictWeakCompare's second_argument_type. and InputIterator2's value_type is convertable to a type in OutputIterator's set of value_types.
OutputIteratoris a model of Output Iterator.
StrictWeakCompareis a model of Strict Weak Ordering.
Precondition
The ranges [first1, last1) and [first2, last2) shall be sorted with respect to comp.
The resulting range shall not overlap with either input range.

The following code snippet demonstrates how to use set_difference to compute the set difference of two sets of integers sorted in descending order.

...
int A1[6] = {9, 6, 5, 4, 3, 1, 0};
int A2[5] = {9, 7, 5, 3, 1};
int result[3];
int *result_end = thrust::set_difference(A1, A1 + 6, A2, A2 + 5, result, thrust::greater<int>());
// result is now {6, 4, 0}
See also
http://www.sgi.com/tech/stl/set_difference.html
includes
set_union
set_intersection
set_symmetric_difference
sort
is_sorted