[Issue 16659] New: Clarify mutating while iterating rules
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Nov 3 01:03:17 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16659
Issue ID: 16659
Summary: Clarify mutating while iterating rules
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dlang.org
Assignee: nobody at puremagic.com
Reporter: shachar at shemesh.biz
Consider the following program:
int[int] hash;
..
foreach( key, ref value; hash ) {
if( value>12 )
hash.remove(key);
}
There is no reference in https://dlang.org/spec/hash-map.html whether this is
legal or not (i.e. - removing an element from the hash while iterating it).
According to http://dlang.org/spec/statement.html#ForeachStatement, this seems
forbidden (in which case it needs to be documented in the first link), but a
forum discussion seemed to gravitate toward needing to allow this (as C++ does,
at least since C++14).
--
More information about the Digitalmars-d-bugs
mailing list