By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,849 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,849 IT Pros & Developers. It's quick & easy.

how to implement a remove_if predicate with iterators vector

P: n/a
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.
Jul 22 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.