| | | | | |

Set Difference

template <class I1, class I2, class I3>
void g_set_difference(I1 beg1, I1 end1, I2 beg2, I2 end2, I3 dest)
// range3 = range1 difference range2
{
  while (beg1 != end1 && beg2 != end2)
  {
    if ((*beg2) < (*beg1))
    {
      ++beg2;
    }
    else if ((*beg1) < (*beg2))
    {
      *dest++ = *beg1++;
    }
    else
    {
      ++beg1;
      ++beg2;
    }
  }
  while (beg1 != end1)
    *dest++ = *beg1++;
}

| | Top of Page | 8. Generic Set Algorithms - 6 of 7