set of iterators?

dear all,

I am trying to use a set of iterators, like this

set< map<class_a*,class_b*>::iterator > todelete;

the compiler does not accept it. Does anyone know why?

many thanks in advance
Your compiler probably complains because iterators don't have ordering nor are hashable.
Anyway: Storing a mutable object in a set? Are you crazy? :D

The elements you store in the set must support operator< or overload of std::less. There is no operator< for map iterators so that's why it doesn't work.

rapidcoder wrote:
Storing a mutable object in a set? Are you crazy?

They are not mutable. You can't get access to non-const references to the elements in the set unless you use const_cast.
Last edited on
ok, thanks both of you for the clear answers!

They are not mutable. You can't get access to non-const references to the elements in the set unless you use const_cast.


Wrong. Const != immutable. Iterators are inherently mutable / stateful by definition. That you can't modify them through the set API, doesn't mean you can't do it in some other way.
Last edited on
Are you talking about that the iterators can be invalidated while being in the set?
Not only invalidated, but just modified in any way affecting equality / ordering / hash. E.g. just calling ++ on them. How do you compare / hash iterators? Because there is no sane way to do that, STL doesn't provide ordering / hashing for iterators by default. They know it would be a very bad idea to use them in sets / map keys and it would easily break in very nasty ways.
Last edited on
Topic archived. No new replies allowed.