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.
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.