Hi,
I want to combine std::unique and std::set_difference into one single procedure.
For instance, I have now this
Code:
// A & B are both already sorted
new_end = std::unique(A->begin(), A->end());
std::set_difference(A->begin(), new_end(), B->begin(), B->end(), C->begin())
//I want to create a single produce mixing both, so that while scanning A and filtering out duplicates, I could also get the elements that are present in A, but not in the B.
template <class ForwardIterator>
ForwardIterator unique ( ForwardIterator first, ForwardIterator last ) {
ForwardIterator result=first;
while (++first != last) {
if (!(*result == *first))
*(++result)=*first;
}
return ++result;
}
template <class InputIterator1, class InputIterator2, class OutputIterator>
OutputIterator set_difference ( InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result ) {
while (first1!=last1 && first2!=last2) {
if (*first1<*first2) *result++ = *first1++;
else if (*first2<*first1) first2++;
else { first1++; first2++; }
}
return copy(first1,last1,result);
}
I would appreciate some help with this