[UPDATE] 03Jan2011 : Please note that the following works ONLY because a and b are “sorted” already
say we have two sets
a = [1,2,34]
b = [2,4]
and i want to perform the set difference operation:
a = a/b OR a = a-b
that is remove from a the elements that are also present in b.
then is the following c++ solution valid?
a.erase(set_difference(a.begin(), a.end(), b.begin(), b.end(), a.begin()), a.end());
i noticed that the following
set_difference(a.begin(), a.end(), b.begin(), b.end(), a.begin());
changed a in to
and returned an iterator to the 3 to the left of 4. this remined me of the erase-remove idiom hence this post.
is it ok to do this?