| | | | | |

Set Intersection

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



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