Skip to main content
gamedev.net
🔒 Locked

STLPort set::iterator

Started by J_Vitel 0 replies 1.2k views
Original Post
J_Vitel
J_Vitel
I've recently moved from Borland C++ Builder 5 to 6 and I found that STLPort's containers such as set and multiset only supports const_iterators. the next is from _set.h:

  typedef typename _Rep_type::const_iterator const_iterator;  
  typedef const_iterator iterator;
In several of my programs, I change properties of many objects wich are stored within a set, so I wonder if is it good idea to modify _set.h in order to make it support non const iterators as the previous version of Borland's STL thanks in advance.
My site Jvitel.com
Fruny
Fruny
No. This is normal. Since the value of a set element doubles as its 'key' (unlike map where they are separate, a const key and a non-const value.), you are not allowed to modify set elements in-place: doing so might invalidate the set's ordering properties. If you want to change such an element, you need to remove the original from the set and insert a new one.

If you really know what you are doing, a const_cast can remove the constness.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.