c++ - Find 'new' items from two containers -


i have 2 containers (the actual container flexible, unsorted vs sorted doesn't matter me, whatever works best answering question i'll use) contain data. want compare these 2 containers, , either remove 'duplicates' second, or create new container 'new' values.

by duplicate/newi mean following: container 1 contains: [1, 2, 4, 8, 16] container 2 contains: [1, 2, 4, 16, 32]

after running algorithm, new container (or modified container 2) should contain: container 3 contains: [32]

notice not want '8' in new container (or modified container) want find 'new' values.

i implement naive , slow program myself, i'm looking elegant , efficient way achieve (boost fine if stl not provide necessary tools/algos without rolling own, otherwise rolling own fine too).

so... 'best' (read: elegant , efficient) way this?

thanks in advance.

p.s. if @ relevant, i'm using write 'diffing' tool exported functions dll. have number of large dlls , want find 'new' exports in latest builds of dlls.

looks stl set_difference might right you. example here:

// set_difference example #include <iostream> #include <algorithm> #include <vector> using namespace std;  int main () {   int first[] = {5,10,15,20,25};   int second[] = {50,40,30,20,10};   vector<int> v(10);                           // 0  0  0  0  0  0  0  0  0  0   vector<int>::iterator it;    sort (first,first+5);     //  5 10 15 20 25   sort (second,second+5);   // 10 20 30 40 50    it=set_difference (first, first+5, second, second+5, v.begin());                                                // 5 15 25  0  0  0  0  0  0  0    cout << "difference has " << int(it - v.begin()) << " elements.\n";    return 0; } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -