how to implement a remove_if predicate with iterators vector

M

marco_segurini

Hi,

I am trying to solve this problem:

I have a vector V1 that is not empty and a vector V2 that contains some
iterator that point to V1 elements. Now I want to remove the V1 elements
that V2 elements reference using erase/remove_if idiom.

////////
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <vector>

template <class typeVectorItem, class typeVector>
class find_if_vector_t
: public std::binary_function<typeVectorItem, typeVector, bool>
{
public:
explicit find_if_vector_t() {}

bool operator()(const typeVectorItem &Item, const typeVector
&Vect) const
{
return ???;
}
};

int main()
{
// Create/Initialize a integers vector
std::vector<int> vInt;
for (int i=0; i<10; ++i)
vInt.push_back(i);

// Create a vector containing the iterator that
// reference the odd integer of the 'vInt' vector
std::vector<int>::iterator iter;
std::vector<std::vector<int>::iterator> vIter;
for (iter=vInt.begin(); iter!=vInt.end(); ++iter)
{
if (*iter % 2)
vIter.push_back(iter);
}

// Erase the elements
vInt.erase( std::remove_if(vInt.begin(), vInt.end()
, std::bind2nd(find_if_vector_t<int,
std::vector<std::vector<int>::iterator> >(),vIter))
, vInt.end());

return 0;
}
////////

Thanks for any help.
Marco.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top