Re: [GD-Windows] Array foreach in scripting languages
Brought to you by:
vexxed72
From: Jon W. <hp...@mi...> - 2006-08-14 01:09:29
|
What's confusing is that your code uses the name DynamicArray (which I suppose is close to ArrayList in .NET), and your C++ test sample probably used std::vector, but you keep referring to the container as a "list". They are very different kinds of containers. You will note that C++ allows you to insert and delete objects in a std::list, but not in a std::vector. The reason is that vectors are guaranteed to be contiguous, and thus iterators (which may be simple pointers) would get invalidated when resizing the underlying storage. Meanwhile, when deleting from a list, the only iterator that gets invalidated is an iterator pointing to the element being deleted. Cheers, / h+ Carsten Orthbandt wrote: > The obvious question is how should an active iterator react if the traversed list > changes? To answer this, I simply tried it out in two languages I know that do > provide both dynamic arrays and foreach: STL, Tcl and C#. > |