.\" ident @(#)set_difference.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH set_difference 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2set_difference\fP \ - A basic set operation for constructing a sorted difference. .SH SYNOPSIS .br #include .br template .RE .RS 1 OutputIterator .RE .RS 0 set_difference (InputIterator1 first1, .RE .RS 20 InputIterator1 last1, .br InputIterator2 first2, .br InputIterator2 last2, .br OutputIterator result); .RE .RS 0 template .RE .RS 1 OutputIterator .RE .RS 0 set_difference (InputIterator1 first1, .RE .RS 20 InputIterator1 last1, .br InputIterator2 first2, .br InputIterator2 last2, .br OutputIterator result, Compare comp); .SH DESCRIPTION The set_difference algorithm constructs a sorted difference that includes copies of the elements that are present in the range \f2[first1, last1)\fP but are not present in the range \f2[first2, last2)\fP. It returns the end of the constructed range. As an example, assume we have the following two sets: \f21 2 3 4 5\fP and \f23 4 5 6 7\fP The result of applying set_difference is the set: \f21 2\fP 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 (\f2<\fP), unless an alternative comparison operator (\f2comp\fP) 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. .SH COMPLEXITY At most \f2((last1 - first1) + (last2 - first2)) * 2 -1\fP comparisons are performed. .SH EXAMPLE .RE .RS 0 // .br // set_diff.cpp .br // .br #include .br #include .br #include .br using namespace std; .br int main() .RE .RS 1 { .RE .RS 0 //Initialize some sets .br int a1[10] = {1,2,3,4,5,6,7,8,9,10}; .br int a2[6] = {2,4,6,8,10,12}; .br set > all(a1+0, a1+10), even(a2+0, a2+6), .RE .RS 20 odd; .RE .RS 0 .br //Create an insert_iterator for odd .br insert_iterator > > .RE .RS 15 odd_ins(odd, odd.begin()); .RE .RS 0 .br //Demonstrate set_difference .br cout << "The result of:" << endl << "{"; .br copy(all.begin(),all.end(), .RE .RS 4 ostream_iterator(cout," ")); .RE .RS 0 cout << "} - {"; .br copy(even.begin(),even.end(), .RE .RS 4 ostream_iterator(cout," ")); .RE .RS 0 cout << "} =" << endl << "{"; .br set_difference(all.begin(), all.end(), .RE .RS 14 even.begin(), even.end(), odd_ins); .RE .RS 0 copy(odd.begin(),odd.end(), .RE .RS 4 ostream_iterator(cout," ")); .RE .RS 0 cout << "}" << endl << endl; .br return 0; .RE .RS 1 } .br .RE .RS 0 Program Output .RE .RS 0 .br The result of: .br {1 2 3 4 5 6 7 8 9 10 } - {2 4 6 8 10 12 } = .br {1 3 5 7 9 } .SH WARNINGS If your compiler does not support default template parameters, then you always need to supply the \f2Compare\fP template argument and the \f2Allocator\fP template argument. For instance, you need to write: \f2set allocator >\fP instead of: \f2set\fP If your compiler does not support namespaces, then you do not need the using declaration for \f2std\fP. .SH SEE ALSO includes, set, set_union,_set_intersection, set_symmetric_difference