# sort

## set_symmetric_difference

`template <class InIter1, class InIter2, class OutIter>    OutIter set_symmetric_difference(InIter1 start1, InIter1 end1,                 InIter2 start2, InIter2 end2, OutIter result); template <class InIter1, class InIter2, class OutIter, class Comp>     OutIter set_symmetric_difference(InIter1 start1, InIter1 end1,                 InIter2 start2, InIter2 end2, OutIter result,                 Comp cmpfn);`

The set_symmetric_difference( ) algorithm produces a sequence that contains the symmetric difference between the two ordered sets defined by start1, end1 and start2, end2. That is, the resultant set contains only those elements that are not common to both sets. The result is ordered and put into result. It returns an iterator to the end of the result.

The second form allows you to specify a comparison function that determines when one element is less than another.

 Programming Tip One of the more interesting algorithms is transform( ) because it modifies each element in range according to a function that you provide. For example, the following program uses a simple transformation function called xform( ) to square the contents of a list. Notice that the resulting sequence is stored in the same list that provided the original sequence. `// An example of the transform algorithm. #include #include #include using namespace std; // A simple transformation function. int xform(int i) { return i * i; // square original value } int main() { list xl; int i; // put values into list for(i=0; i<10; i++) xl.push_back(i); cout << "Original contents of xl: "; list::iterator p = xl.begin(); while(p != xl.end()) { cout << *p << " "; p++; } cout << endl; // transform xl p = transform(xl.begin(), xl.end(), xl.begin(), xform); cout << "Transformed contents of xl: "; p = xl.begin(); while(p != xl.end()) { cout << *p << " "; p++; } return 0; } ` The output produced by the program is shown here: ` Original contents of xl: 0 1 2 3 4 5 6 7 8 9 Transformed contents of xl: 0 1 4 9 16 25 36 49 64 81 ` As you can see, each element in xl has been squared. C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539