Re: [GD-Windows] Array foreach in scripting languages
Brought to you by:
vexxed72
|
From: Jon W. <hp...@mi...> - 2006-08-14 17:15:43
|
Carsten Orthbandt wrote:
> I tested this with both, my DynamicArray and std::vector.
> Since we're talking about a scripting language here, the
> actual implementation doesn't matter. It can be alinked
> list, contigous memory block, hashmap, whatever.
>
The actual implementation DOES matter, because std::list<> makes the
guarantee that you can delete items ahead of, or behind, the current
iterator, without ill effects. An array, on the other hand, explicitly
forbids that practice.
Thus, depending on which semantic you prefer to expose, you should
choose one, or the other. That's one of the reasons that C++ defines
both data types, and lets the programmer decide.
In the case where you're using a data type that invalidates iterators, I
suggest that you (at least in debug mode) detect the invalid iterator
and assert out on first use. The sooner you detect potentially invalid
usage, the better.
Cheers,
/ h+
|