includes, set_difference, set_intersection, set_symmetric_difference and set_union. : set_difference « STL Algorithms Merge « C++ Tutorial






#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
   const int SIZE1 = 10, SIZE2 = 5, SIZE3 = 20;
   int a1[ SIZE1 ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
   int a2[ SIZE2 ] = { 4, 5, 6, 7, 8 };
   int a3[ SIZE2 ] = { 4, 5, 6, 11, 15 };

   if ( includes( a1, a1 + SIZE1, a2, a2 + SIZE2 ) )
      cout << "\na1 includes a2";
   else
      cout << "\na1 does not include a2";
      
   if ( includes( a1, a1 + SIZE1, a3, a3 + SIZE2 ) )
      cout << "\na1 includes a3";
   else
      cout << "\na1 does not include a3";

   int difference[ SIZE1 ];
   int *ptr = set_difference( a1, a1 + SIZE1, a2, a2 + SIZE2, difference );

   int intersection[ SIZE1 ];
   ptr = set_intersection( a1, a1 + SIZE1, a2, a2 + SIZE2, intersection );

   int symmetric_difference[ SIZE1 ];
   ptr = set_symmetric_difference( a1, a1 + SIZE1,a2, a2 + SIZE2, symmetric_difference );

   int unionSet[ SIZE3 ];
   ptr = set_union( a1, a1 + SIZE1, a3, a3 + SIZE2, unionSet );
   return 0;
}








28.4.set_difference
28.4.1.Determine elements in one set but not in another set
28.4.2.Determine elements of first range without elements of second range by using set_difference()
28.4.3.includes, set_difference, set_intersection, set_symmetric_difference and set_union.