I’m trying to call the set_difference function, and put the result on a std::list. In theory, it is possible to do this on any sorted container, right?
list<int> v;
list<int> l1;
list<int> l2;
list<int>::iterator it;
//l1 and l2 are filled here
l1.sort();
l2.sort();
it=set_difference(
l1.begin(),
l1.end(),
l2.begin(),
l2.end(),
v.begin()
);
v is returning as an empty list, however. Is it because I can’t use it on the list container?
It’s because
v.begin()is the beginning of an empty sequence. The elements get copied to pretty much anywhere. Replace it withstd::back_inserter(v). That will give you an iterator that knows how to insert intov.