 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
fifth8118 Guest
|
Posted: Sat Nov 11, 2006 12:58 am Post subject: remove_if under visual c++.net 2005 |
|
|
Hi, all:
I write a vector contain complex objects, and use flag to identify
them, when flag=1, then use remove_if to delete the element, following
is a simplified form of that code which work well under g++ 3.4.3, but
under Visual C++.net 2005, it cannot be compiled, the message is
"...... error C3861: remove_if: cannot find identifier", can anybody
help?
///////////////////////////////////////////////////////////////
#include "stdafx.h" //Deleted under Linux
#include <vector>
#include <iostream>
struct A {
int value;
int flag;
friend class IsFlag;
}a;
class IsFlag {
public:
bool operator() (const A &rhs) {
return (rhs.flag ==1)?true:false;
}
};
int main () {
int i;
std::vector <A> N;
for (i=0; i<10; i++) {
a.value = i;
a.flag = 0;
if (i%3 == 0) a.flag = 1;
N.push_back(a);
}
N.erase(remove_if(N.begin(),N.end(),IsFlag()),N.end());
return 1;
}
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
red floyd Guest
|
Posted: Sat Nov 11, 2006 3:57 am Post subject: Re: remove_if under visual c++.net 2005 |
|
|
fifth8118 wrote:
| Quote: | Hi, all:
I write a vector contain complex objects, and use flag to identify
them, when flag=1, then use remove_if to delete the element, following
is a simplified form of that code which work well under g++ 3.4.3, but
under Visual C++.net 2005, it cannot be compiled, the message is
"...... error C3861: remove_if: cannot find identifier", can anybody
help?
|
That's because there is no standard lib function remove_if(), you have
to use remove_copy_if().
Does anyone know if this is slated to be fixed in C++0x?
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Carl Barron Guest
|
Posted: Sat Nov 11, 2006 6:03 am Post subject: Re: remove_if under visual c++.net 2005 |
|
|
In article <Oq45h.11907$B31.1040 (AT) newssvr27 (DOT) news.prodigy.net>, red floyd
<no.spam (AT) here (DOT) dude> wrote:
| Quote: | fifth8118 wrote:
Hi, all:
I write a vector contain complex objects, and use flag to identify
them, when flag=1, then use remove_if to delete the element, following
is a simplified form of that code which work well under g++ 3.4.3, but
under Visual C++.net 2005, it cannot be compiled, the message is
"...... error C3861: remove_if: cannot find identifier", can anybody
help?
That's because there is no standard lib function remove_if(), you have
to use remove_copy_if().
see sec 25.2.7 of the c++98 adapted standard. Its there. If your |
standard lib does not have remove_if its non-conforming. Complain to
your vendor grep the header algorithm for remove_if and it should be
there.......
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Meador Inge Guest
|
Posted: Sat Nov 11, 2006 6:04 am Post subject: Re: remove_if under visual c++.net 2005 |
|
|
red floyd wrote:
| Quote: | That's because there is no standard lib function remove_if(),
Yes there is. |
The problem is that the OP does not "#include <algorithm>".
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Jakob Bieling Guest
|
Posted: Sat Nov 11, 2006 10:10 am Post subject: Re: remove_if under visual c++.net 2005 |
|
|
fifth8118 wrote:
| Quote: | "...... error C3861: remove_if: cannot find identifier" [..]
///////////////////////////////////////////////////////////////
#include "stdafx.h" //Deleted under Linux
#include <vector
#include <iostream
struct A {
int value;
int flag;
friend class IsFlag;
}a;
class IsFlag {
public:
bool operator() (const A &rhs) {
return (rhs.flag ==1)?true:false;
}
};
int main () {
int i;
std::vector <A> N;
for (i=0; i<10; i++) {
a.value = i;
a.flag = 0;
if (i%3 == 0) a.flag = 1;
N.push_back(a);
}
N.erase(remove_if(N.begin(),N.end(),IsFlag()),N.end());
return 1;
}
|
Other than what others have said, I want to add, that you also need to
change "remove_if" to "std::remove_if". But I am not really sure about how
the lookup is done here, so you may very well not need it. Maybe someone
else can clarify.
regards
--
jb
(reply address in rot13, unscramble first)
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Carlos Moreno Guest
|
Posted: Sat Nov 11, 2006 10:10 am Post subject: Re: remove_if under visual c++.net 2005 |
|
|
Meador Inge wrote:
| Quote: | red floyd wrote:
That's because there is no standard lib function remove_if(),
Yes there is.
The problem is that the OP does not "#include <algorithm>".
|
And did not qualify it to std (either prefixing and calling
it std::remove_if, or by using namespace std;)
Carlos
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Meador Inge Guest
|
Posted: Sat Nov 11, 2006 9:03 pm Post subject: Re: remove_if under visual c++.net 2005 |
|
|
Carlos Moreno wrote:
| Quote: | And did not qualify it to std (either prefixing and calling
it std::remove_if, or by using namespace std;)
I thought about that as well. However, for this specific case the std:: |
is not needed. The reason being that the vector is already qualified
thus Koenig lookup will kick in and find remove_if.
--Meador
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
red floyd Guest
|
Posted: Wed Nov 15, 2006 6:39 am Post subject: Re: remove_if under visual c++.net 2005 |
|
|
fifth8118 wrote:
| Quote: |
"remove_if" question redacted.
|
To everyone. I claimed there was no such standard Lib function as
remove_if. For some reason I read it as "copy_if".
I apologize for the senior moment.
Of course remove_if exists, and OP's problem is that he didn't #include
<algorithm>
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Daniel Krügler Guest
|
Posted: Wed Nov 15, 2006 7:47 am Post subject: Re: remove_if under visual c++.net 2005 |
|
|
Meador Inge schrieb:
| Quote: | Carlos Moreno wrote:
And did not qualify it to std (either prefixing and calling
it std::remove_if, or by using namespace std;)
I thought about that as well. However, for this specific case the std::
is not needed. The reason being that the vector is already qualified
thus Koenig lookup will kick in and find remove_if.
|
The fully qualified name std::remove_if is indeed necessary for
portable programs. Whether ADL applies or not depends on the
question whether std::vector<A>::iterator is a user-defined type found
by ADL or if it is not (e.g. a raw pointer).
There exists good chances, that your favourite compiler will accept the
unqualified call in debug mode but hastens to add that it doesn't like
it in release mode (depending on your compiler-specific settings, of
course).
Greetings from Bremen,
Daniel Krügler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
red floyd Guest
|
Posted: Thu Nov 16, 2006 3:57 am Post subject: Re: remove_if under visual c++.net 2005 |
|
|
[note to moderators -- not sure if my previous post got eaten by the outage]
To all.
I apologize for my idiocy. I replied to the OP that there was no such
thing as "remove_if". For some reason, my brain read that his question
as referring to "copy_if". Senior moment.
Of course remove_if exists, and the OP's problem was the lack of
#include <algorithm>
Apologies for my stupidity.
red floyd
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|