What you're asking for is that vec3
be the intersection of the other two. Jalf demonstrates how to populate vec3
using the std::set_intersection
function from the <algorithm>
header. But remember that for the set functions to work, the vectors must be sorted.
Then you want vec1
and vec2
to be the difference between themselves and vec3
. In set notation:
vec1 := vec1 \ vec3;
vec2 := vec2 \ vec3;
You can use the std::set_difference
function for that, but you can't use it to modify the vectors in-place. You'd have to compute another vector to hold the difference:
std::vector<foo> temp;
std::set_difference(vec1.begin(), vec1.end(),
vec3.begin(), vec3.end(),
std::back_inserter(temp));
vec1 = temp;
temp.clear();
std::set_difference(vec2.begin(), vec2.end(),
vec3.begin(), vec3.end(),
std::back_inserter(temp));
vec2 = temp;