Re: STL - erasing from a set
On Nov 19, 7:14 am, Andrey <akr...@gmail.com> wrote:
You said,
This basically means you would need a
temporary container and it does not remove the mentioned elements from
the source set.
I understand that, but the problem is that this temporary container
cannot be a new (empty) set... it needs to be something that is filled
to the necessary capacity already.
Just the opposite, really. If the target container is a set, it
should be empty. IIRC, someone has already posted the correct
solution: use an insertion iterator for the output, e.g.:
I wrote another sample program to
see if I could I could get set_symmetric_difference to work:
#include <iostream>
#include <cstdlib>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
set<int> set_int;
set_int.insert(2);
set_int.insert(1);
set_int.insert(3);
set<int> set2_int;
set2_int.insert(2);
set<int> set_diff;
set_symmetric_difference(set_int.begin(), set_int.end(),
set2_int.begin(), set2_int.end(), set_diff.begin());
set_symmetric_difference(set_int.begin(), set_int.end(),
set2_int.begin(), set2_int.end(),
std::inserter(set_diff,
set_diff.begin()));
return 0;
}
--
James Kanze
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]