Compile error when using remove_if on a map
Levente Farkas
!spam-lfarkas@mindmaker.hu
Tue May 23 01:13:00 GMT 2000
you have to define foo as:
--------------
class foo
{
public:
bool operator()(const pair<const int,int>& item);
};
--------------
but the best would be
--------------
class foo
{
public:
bool operator()(const map<int,int>::value_type& item);
};
--------------
"Eduardo T. Solis" wrote:
>
> I've been trying to make the sample code compile but it always gives me a
> compile time error as follows...
>
> <snip>
> ...../include/g++-3/stl_algo.h:534: non-static const member `const int
> pair<const int,int>::first', can't use default assignment operator
>
> My question:
> 1. Am I allowed to use the remove_if generic algorithm with a map base on
> the standards?
> 2. Is my use of the remove_if generic algorithm syntactically correct?
> 3. Is this a bug in my code or in libstdc++?
> 4. Is there any work around for this? I can traverse the map manually and
> check each item but is there any other work around aside from this?
>
> Ed
>
> -------- Start of Sample code ------------
>
> #include <algorithm>
> #include <map>
>
> class foo
> {
> public:
> bool operator()(const pair<int,int>& item);
> };
>
> bool foo::operator()(const pair<int, int>& item)
> {
> // For the sake of this example
> // we'll just return false
> return false;
> }
>
> void main()
> {
> map<int, int> m;
> remove_if(m.begin(), m.end(), foo());
> }
--
-- lfarkas
"The only thing worse than not knowing the truth is
ruining the bliss of ignorance."
More information about the Libstdc++
mailing list