home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 May / VPR9705A.ISO / VPR_DATA / PROGRAM / CBTRIAL / SETUP / DATA.Z / SET_UNIN.CPP < prev    next >
Text File  |  1997-02-14  |  892b  |  33 lines

  1.  #include <algorithm>
  2.  #include <set>
  3.  
  4.  using namespace std;
  5.  
  6.  int main ()
  7.  {
  8.    //
  9.    // Initialize some sets.
  10.    //
  11.    int a2[6]  = {2,4,6,8,10,12};
  12.    int a3[4]  = {3,5,7,8};
  13.    set<int, less<int> >  even(a2+0, a2+6), result, smalll(a3+0, a3+4);
  14.    //
  15.    // Create an insert_iterator for result.
  16.    //
  17.    insert_iterator<set<int, less<int> > > res_ins(result, result.begin());
  18.    //
  19.    // Demonstrate set_union.
  20.    //
  21.    cout << "The result of:" << endl << "{";
  22.    copy(smalll.begin(),smalll.end(), ostream_iterator<int>(cout," "));
  23.    cout << "} union {";
  24.    copy(even.begin(),even.end(), ostream_iterator<int>(cout," "));
  25.    cout << "} =" << endl << "{";
  26.    set_union(smalll.begin(), smalll.end(), even.begin(), even.end(), res_ins);
  27.    copy(result.begin(),result.end(), ostream_iterator<int>(cout," "));
  28.    cout << "}" << endl << endl;
  29.  
  30.    return 0;
  31.  }
  32.  
  33.