Hi, I have two vector<int> objects with the values 1,2,3,4,5,6 and 1,2,4,6 respectfully. Is there a function available within std which will give me a vector<int> object with 3, 5 (subtraction). Thanks, Barry
> I have two vector<int> objects with the values 1,2,3,4,5,6 and 1,2,4,6 > respectfully. Is there a function available within std which will give > me a vector<int> object with 3, 5 (subtraction). If you use std::set instead of vector, then you've got std::set_difference
> Hi, > > I have two vector<int> objects with the values 1,2,3,4,5,6 and 1,2,4,6 > respectfully. Is there a function available within std which will give > me a vector<int> object with 3, 5 (subtraction). That's not subtraction. And, as far as I know, there is nothing in the standard library that will do exacly that. But you can use std::tranform to loop over the first vector and output (via std::back_inserter) the resultant vector. Just write a functor that uses std::find to search the second vector. HTH
> std::set_difference has nothing to do with std::set. It only requires that iterator ranges represent a set (no duplicated values) sorted in ascending order Of course. Sorry, that was temporary blackout :).
Igor R. wrote: >> I have two vector<int> objects with the values 1,2,3,4,5,6 and 1,2,4,6 >> respectfully. Is there a function available within std which will give >> me a vector<int> object with 3, 5 (subtraction). > > If you use std::set instead of vector, then you've got > std::set_difference std::set_difference has nothing to do with std::set. It only requires that iterator ranges represent a set (no duplicated values) sorted in ascending order; which is already the case here. If it is not the case, std::sort and std::unique will do the job. The OP can directly use std::set_difference on his data. -- Michael
AnonMail2005@gmail.com wrote: >> Hi, >> >> I have two vector<int> objects with the values 1,2,3,4,5,6 and 1,2,4,6 >> respectfully. Is there a function available within std which will give >> me a vector<int> object with 3, 5 (subtraction). > > That's not subtraction. IMO The OP confused subtraction and difference. > And, as far as I know, there is nothing in > the standard library that will do exacly that. std::set_difference does. -- Michael