.\" ident @(#)set_union.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH set_union 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2set_union\fP \ - A basic set operation for constructing a sorted union. .SH SYNOPSIS .br #include .br template .RE .RS 1 OutputIterator .RE .RS 0 set_union (InputIterator1 first1, InputIterator1 last1, .RE .RS 14 InputIterator2 first2, InputIterator2 last2, .br OutputIterator result); .RE .RS 0 template .RE .RS 1 OutputIterator .RE .RS 0 set_union (InputIterator1 first1, InputIterator1 last1, .RE .RS 14 InputIterator2 first2, InputIterator2 last2, .br OutputIterator result, Compare comp); .SH DESCRIPTION The_set_union algorithm constructs a sorted union of the elements from the two ranges. It returns the end of the constructed range. set_union is stable, which means that if an element is present in both ranges, the one from the first range is copied. The result of set_union is undefined if the result range overlaps with either of the original ranges. Note that set_union does not merge the two sorted sequences. If an element is present in both sequences, only the element from the first sequence is copied to \f2result\fP. (Use the merge algorithm to create an ordered merge of two sorted sequences that contains all the elements from both sequences.) set_union assumes that the sequences 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_unin.cpp .br // .br #include .br #include .br #include .br using namespace std; .br .br int main() .RE .RS 1 { .RE .RS 0 .br //Initialize some sets .br int a2[6] = {2,4,6,8,10,12}; .br int a3[4] = {3,5,7,8}; .br set > even(a2+0, a2+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_union .br cout << "The result of:" << endl << "{"; .br copy(small.begin(),small.end(), .RE .RS 4 ostream_iterator(cout," ")); .RE .RS 0 cout << "} union {"; .br copy(even.begin(),even.end(), .RE .RS 4 ostream_iterator(cout," ")); .RE .RS 0 cout << "} =" << endl << "{"; .br set_union(small.begin(), small.end(), .RE .RS 9 even.begin(), even.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 } union {2 4 6 8 10 12 } = .br {2 3 4 5 6 7 8 10 12 } .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_intersection, set_difference, set_symmetric_difference