473,320 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to implement a remove_if predicate with iterators vector

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
0 1473

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: CupOfWater | last post by:
Hi, I'm getting some errors using remove_if that I can not fix at all. Let me paste my code and also the error here. I went on IRC and people were mostly no help. The compiler is g++ 3.2.3. ...
5
by: Wang Tong | last post by:
I have the following code, which removes a pair (string, int) from the set. I defined a predicate that returns true if the string value matches. But I am getting compiler error on the remove_if...
2
by: marco_segurini | last post by:
Hi, if I compile the following code I get the error: RemoveIf.cpp(19) : error C2914: 'remove_if' : cannot deduce template argument as function argument is ambiguous #include <algorithm>...
4
by: hall | last post by:
I accidently overloaded a static member function that I use as predicate in the std::sort() for a vector and ended up with a compiler error. Is this kind of overload not allowed for predicates and...
3
by: codefixer | last post by:
Hello, I am trying to understand if ITERATORS are tied to CONTAINERS. I know the difference between 5 different or 6(Trivial, on SGI). But what I fail to understand is how can I declare all 5...
2
by: Adam Hartshorne | last post by:
Hi All, I want to do the following, I have a std::vector<Patch> called say vs. Now there is a bool variable in the class called outlier, which may be access by getOutlierStatus() method. ...
2
by: ma740988 | last post by:
typedef std::vector < std::complex < double > > complex_vec_type; // option1 int main() { complex_vec_type cc ( 24000 ); complex_vec_type dd ( &cc, &cc ); } versus
3
by: Jon Rea | last post by:
Hello all, Sorry if this is long, but I wanted to be specific... Can anyone shed any light on the following errors in the context of the following example code: cullMethod1(); // compiles,...
1
by: ASAXE | last post by:
Hi, I have a vector of pair<string, string> in my code which holds the list of tokens found in a particular file. The first string is the file name and the second is the token. The vector...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.