On 08/12/2011 03:13 PM, bearophile wrote:
Ellery Newcomer:
in std.container, the stable* container functions advocate that they do
not invalidate the ranges of their containers. What does it mean to
invalidate a range?
Generally modifying a collection while you iterate on it causes troubles. When you
iterate on a range and you modify the range during the iteration Python gives you an
error, because the "for" temporary sets boolean inside the iteratee. In D this
problem was avoided in another way, using those stable functions.
Bye,
bearophile
I am not convinced of this. In the following code, there is definitely a
problem; it just remains to be seen whether the range is invalidated, or
merely noisy according to the specified semantics.
import std.container;
import std.stdio;
import std.array;
void main(){
auto arr = make!(Array!int)([1,2,3]);
auto r = arr[];
writeln(array(r.save()));
arr.stableRemoveAny();
writeln(array(r.save()));
}