473,387 Members | 1,683 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,387 software developers and data experts.

Question Regarding remove_if

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.

Now I want to remove all "Patch"es in the vector dataPatches, whose
outlier variable is set to true.

Now my immediate thought was to use remove_if in the following way

vs.erase(std::remove_if(vs.begin(), vs.end(), getOutlierStatus()),
vs.end());

however this is obviously not correct way to call getOutlierStatus().

So I am wondering how I should go about doing this?

Any help much appreciated,

Adam
Apr 26 '06 #1
2 1935
Adam Hartshorne <ad**@dcs.warwick.ac.uk> writes:
vs.erase(std::remove_if(vs.begin(), vs.end(), getOutlierStatus()),

Maybe mem_fun(Patch::getOutlierStatus) instead of getOutlierStatus()

with #include <functional>

Apr 26 '06 #2
Adam Hartshorne wrote:
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.

Now I want to remove all "Patch"es in the vector dataPatches, whose
outlier variable is set to true.

Now my immediate thought was to use remove_if in the following way

vs.erase(std::remove_if(vs.begin(), vs.end(), getOutlierStatus()),
vs.end());

however this is obviously not correct way to call getOutlierStatus().

So I am wondering how I should go about doing this?


vs.erase(
std::remove_if(
vs.begin(),
vs.end(),
std::mem_fun_ref(&Patch::getOutlierStatus)
),
vs.end()
);

(untested). You need <functional> for this.

Tom
Apr 26 '06 #3

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...
1
by: Paavo K | last post by:
Hi, can anyone tell what is wrong with following code : //..Code class removeTest { public: bool operator()(map<int, string>::value_type &d) const { // Just returning false to simplify...
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>...
0
by: marco_segurini | last post by:
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...
10
by: Piotr | last post by:
In Effective STL item 9 "Choose carefully among erasing options", it has this example: bool badValue(int x); // returns whether x is 'bad' c.erase ( remove_if(c.begin(), c.end(), badValue),...
8
by: Jim Langston | last post by:
There's the thing about iterating though a map or vector when you may delete one of the elements, where you simply assign the iterator to the map.erase() statement or increment it if you don't. ...
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,...
3
by: Angus | last post by:
Hi I have a class CRequest with a function: bool IsFinished() const; I have a list of these CRequests - list<CRequestmylist. I create a function object to find if a CRequest is finished:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.