473,660 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question Regarding remove_if

Hi All,

I want to do the following,

I have a std::vector<Pat ch> called say vs. Now there is a bool variable
in the class called outlier, which may be access by getOutlierStatu s()
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::r emove_if(vs.beg in(), vs.end(), getOutlierStatu s()),
vs.end());

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

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

Any help much appreciated,

Adam
Apr 26 '06 #1
2 1952
Adam Hartshorne <ad**@dcs.warwi ck.ac.uk> writes:
vs.erase(std:: remove_if(vs.be gin(), vs.end(), getOutlierStatu s()),

Maybe mem_fun(Patch:: getOutlierStatu s) instead of getOutlierStatu s()

with #include <functional>

Apr 26 '06 #2
Adam Hartshorne wrote:
Hi All,

I want to do the following,

I have a std::vector<Pat ch> called say vs. Now there is a bool variable
in the class called outlier, which may be access by getOutlierStatu s()
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::r emove_if(vs.beg in(), vs.end(), getOutlierStatu s()),
vs.end());

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

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


vs.erase(
std::remove_if(
vs.begin(),
vs.end(),
std::mem_fun_re f(&Patch::getOu tlierStatus)
),
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
5555
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. Thanks in advance. /usr/include/c++/3.2.3/bits/stl_algo.h: In function `_OutputIter std::remove_copy_if(_InputIter, _InputIter, _OutputIter, _Predicate) ': /usr/include/c++/3.2.3/bits/stl_algo.h:1085: instantiated from `_ForwardIter...
5
1849
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 function: Here is the code: typedef pair<string, int> my_pair; typedef set<my_pair> my_set; typedef my_set::iterator my_set_p;
1
5173
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 code..
2
2448
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> #include <vector>
0
1493
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 elements reference using erase/remove_if idiom. //////// #include <algorithm>
10
5064
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), c.end()); // this is the best way to get rid of objects where badValue returns true when c is a vector, string, or dequeue c.remove_if(badValue); // this is the best way to get rid of objects where badValue returns true when c is a list
8
2136
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. Well, I have this issue where I may delete the map element in 3 different places: for ( map_key_pcmissile::iterator mit = World.Missiles.begin(); mit != World.Missiles.end(); ) { if ( /* Some Condition */ )
3
4142
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, but not what we want - we cant access m_Exclustions
3
2580
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: class is_finished : public std::unary_function<CRequest, bool> {
0
8341
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8754
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8542
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.