Re: Question RE. STL's <set>
Well set is used for the storage and retrieval of data from a collection in which the values of the elements contained are unique and serve as the key values according to which the data is automatically ordered. So when u insert or delete in Set the insert member function returns an iterator that points to the position where the new element was inserted into the set. On insertion and deletion the container will be reordered so ur Iterator may point to someother value on that position.
Use iterator find( const Key& _Key) const; funtion when u want the Iterator of such value.
Re: Question RE. STL's <set>
Actually that is wrong. The only operation which invalidates a std::set iterator is when the element you're pointing to has been removed. Adding other elements or removing other elements doesn't matter. So unless you are removing the element that you added beforehand, you will be fine.
Quote:
Originally Posted by SGI's STL docs
Set has the important property that inserting a new element into a set does not invalidate iterators that point to existing elements. Erasing an element from a set also does not invalidate any iterators, except, of course, for iterators that actually point to the element that is being erased.
Re: Question RE. STL's <set>
That's a new one on me. I was under the same impression as Abdul, that sets were typically implemented as balanced binary trees. Which is what Josuttis says in his book "The C++ Standard Library". Iterators will be invalidated if you insert/delete from a balanced binary tree. Well, let me re-phrase that, iterators *could* be invalidated (depending on the implementation of the iterator).
Viggy
Re: Question RE. STL's <set>
Quote:
Originally Posted by MrViggy
Which is what Josuttis says in his book "The C++ Standard Library". Iterators will be invalidated if you insert/delete from a balanced binary tree. Well, let me re-phrase that, iterators *could* be invalidated (depending on the implementation of the iterator).
Great book, the same one I'm learning from... I'm sure I too remember reading something like that.
Quote:
Originally Posted by Yves M
Actually that is wrong. The only operation which invalidates a std::set iterator is when the element you're pointing to has been removed. Adding other elements or removing other elements doesn't matter. So unless you are removing the element that you added beforehand, you will be fine.
I'll check it out now and see if this works in Visual Studio 2003. I'll let you all know...
Thanks for the great replies everyone :)
Re: Question RE. STL's <set>
Moving of the set elements would only alter the pointers to other nodes. set is a node based container. The object in specific memory location would remain intact because there is no reallocation.
Re: Question RE. STL's <set>
Quote:
and see if this works in Visual Studio 2003.
And this issue has NO BEARING ON VISUAL STUDIO OF ANY VERSION
It has to do with the implementation of STL in the support libraries which is completely independant. Even if you use notepad to edit your files and compile with command line compilers [and I am talking about the same compilers that Visual Studio happens to use], the implementation of std::set will either follow the standard or not. The IDE has nothing to do with it.
Which ius why this question is properly posted in this forum. :D
Re: Question RE. STL's <set>
Heh, yeah didn't mean it that way...
Thanks everyone- it works fine and solves the problem beautifully :)