c++ - Loop over two vectors, remove elements of 1 -


I have the following toy code, whose purpose is to remove the duplicates from the vector:

  zero Overlap_revell (vector & lieutenant; ant & g; act and g; vc2) {for (vector & lieutenant; at & g; :: iterator it1 = wyk 1. beta (); IT1! = Vc 1.and ( ); ++ IT1 (vector & lt; int & gt; :: iterator it2 = vec2.begin (); it2! = Vec2.end (); ++ it2) {if ((* it1) * (* It2)) <10) {vec1.erase (); }}}}  

I am making a slightly more complicated comparison with the actual code, but I did not want to confuse the issue. The problem segment is the fault of partition which essentially follows this execution. Is: I think this is due to the fact that I am removing an element and then continuing the loop on the same vector.

How can I code work? Is this also the correct starting point? Thanks in advance

Try

The basic idea is that you provide function objects As if the truth is returned, if the element should be passed in:

OtherVectorPred {const std :: vector & lt; Int & gt; & Amp; OtherVec; ItemInOtherVectorPred (const std :: vector & lt; int & gt; vec): Other Vec (vec) {} // If true, removeVecsElem should be removed bool operator () (const and removeVecsElem) Const {return (otherVec.find (removeVecsElem)! = ElseVec.end ())}}

Then you can ask to remove your object using an example - your vector What to remove from

  Zero overlap_reval (vector & lt; intT & gt; vc1, vector & gt; int & gt; & vec2) {itemAvailable Practices True IF Item in Other Weekpread (VC2) ; Vector & lt; Int & gt; :: Eraser Eraser bug = std :: remove_if (vec1.begin (), vec1.end (), true if item in other weekpread); Vec1.erase (Erase, vec1.end ()); }  

Comments