Issues with remove_if in VS2010 when using kits

I have the following code.

#include <set> #include <algorithm> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { typedef set<long> MySet; MySet a; for( int i = 0; i < 10; ++i) { a.insert(i); } MySet::iterator start,end,last; start = a.begin(); end = a.end(); last = remove_if(start,end,bind2nd(less_equal<long>(),5)); return 0; } 

What under VS2005 is used for compilation. However, using VS2010, I get the following error:

Error 1 error C3892: '_Next': you cannot assign a variable that is const c: \ program files \ microsoft visual studio 10.0 \ vc \ include \ algorithm

If I make the container a vector, everything will be fine.

I guess something has changed in the standard that I don't know about, can someone shed some light on why this is no longer working?

+6
set stl visual-studio-2010 visual-studio-2005
source share
1 answer

A std::set always saves its elements in sorted order. std::remove_if tries to move items that you do not want to remove before the collection begins. This violates the set of invariants for storing elements in a sorted order.

The code should never have worked. Older compilers might not apply the rules tough enough to let you know that they shouldn't work, but (apparently) your current one.

+6
source share

All Articles