Question Regarding remove_if

A

Adam Hartshorne

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
 
T

Tim Love

Adam Hartshorne said:
vs.erase(std::remove_if(vs.begin(), vs.end(), getOutlierStatus()),


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

with #include <functional>
 
T

Tom Widmer

Adam said:
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
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top