.\" ident @(#)set_intersection.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH set_intersection 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2set_intersection\fP \ - A basic set operation for constructing a sorted intersection. .SH SYNOPSIS .br #include .br template .RE .RS 1 OutputIterator .RE .RS 0 set_intersection (InputIterator1 first1, .RE .RS 21 InputIterator1 last1, .br InputIterator2 first2, .br InputIterator last2, .br OutputIterator result); .RE .RS 0 template .RE .RS 1 OutputIterator .RE .RS 0 set_intersection (InputIterator1 first1, .RE .RS 21 InputIterator1 last1, .br InputIterator2 first2, .br InputIterator2 last2, .br OutputIterator result, Compare comp); .SH DESCRIPTION The set_intersection algorithm constructs a sorted intersection of elements from the two ranges. It returns the end of the constructed range. When it finds an element present in both ranges, set_intersection always copies the element from the first range into \f2result\fP. This means that the result of set_intersection is guaranteed to be stable. The result of set_intersection is undefined if the result range overlaps with either of the original ranges. set_intersection assumes that the ranges are sorted using the default comparison operator less than (\f2<\fP), unless an alternative comparison operator (\f2comp\fP) is provided. .SH COMPLEXITY At most \f2((last1 - first1) + (last2 - first2)) * 2 -1\fP comparisons are performed. .SH EXAMPLE .RE .RS 0 // .br // set_intr.cpp .br // .br #include .br #include .br #include .br using namespace std; .br int main() .RE .RS 1 { .RE .RS 0 .br //Initialize some sets .br int a1[10] = {1,3,5,7,9,11}; .br int a3[4] = {3,5,7,8}; .br set > odd(a1+0, a1+6), .RE .RS 3 result, small(a3+0,a3+4); .RE .RS 0 //Create an insert_iterator for result .br insert_iterator > > .RE .RS 3 res_ins(result, result.begin()); .RE .RS 0 //Demonstrate set_intersection .br cout << "The result of:" << endl << "{"; .br copy(small.begin(),small.end(), .RE .RS 4 ostream_iterator(cout," ")); .RE .RS 0 cout << "} intersection {"; .br copy(odd.begin(),odd.end(), .RE .RS 4 ostream_iterator(cout," ")); .RE .RS 0 cout << "} =" << endl << "{"; .br set_intersection(small.begin(), small.end(), .RE .RS 16 odd.begin(), odd.end(), res_ins); .RE .RS 0 copy(result.begin(),result.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 {3 5 7 8 } intersection {1 3 5 7 9 11 } = .br {3 5 7 } .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_difference, set_symmetric_difference