You are trying to overwrite the contents of a set, by giving left[*u].begin()
as the output argument of set_union
. The elements of a set cannot be modified, since their value determines their position in the set. Even if you could, you would need to grow the container to accommodate the extra elements, not simply overwrite the existing ones; and the output must not overlap with either input range. To summarise: you can't use set_union
to insert the contents of one set into another.
If you want to add the contents of dummy
to left[*u]
, then insert each element:
std::copy(dummy.begin(), dummy.end(), std::inserter(left[*u]));