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

STL remove_if function

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..
return false;
}
};

void testFunction()
{
map<int, string> *m = new map<int, string>;

if(m->empty() == false)
{

m->erase(
remove_if(m->begin(),
m->end(),
removeTest()),
m->>end()
);

}
else cout<<"\n Nothing to remove \n";
}
Visual C++ compiler return this message :

c:\microsoft visual studio\vc98\include\algorithm(317) :
error C2582: 'std::pair<int const ,class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > >' : 'operator ='
function is unavailable

Thanks in advance!
Jul 22 '05 #1
1 5157
On Tue, 17 Feb 2004 19:09:13 +0200 in comp.lang.c++, Paavo K
<ko******@students.oamk.fi> was alleged to have written:
map<int, string> *m = new map<int, string>; .... remove_if(m->begin(),
m->end(),
removeTest()),
m->>end()
);
You cannot use std::remove_if against a std::map. remove_if reorders
elements (perhaps surprisingly, it does not really remove anything) and
elements of a map cannot be reordered.
Visual C++ compiler return this message :

c:\microsoft visual studio\vc98\include\algorithm(317) :
error C2582: 'std::pair<int const ,class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > >' : 'operator ='
function is unavailable


Notice the "const" in the above message. You cannot assign to a
std::pair with a const member.

Jul 22 '05 #2

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. ...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
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...
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...
2
by: Adam Hartshorne | last post by:
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. ...
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,...
1
by: ASAXE | last post by:
Hi, I have a vector of pair<string, string> in my code which holds the list of tokens found in a particular file. The first string is the file name and the second is the token. The vector...
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: 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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.