On Tuesday, 27 November 2012 at 16:08:54 UTC, Andrei Alexandrescu wrote:
As far as I understand you reveal it's impossible to iterate a const(V[K]), which is an implementation bug. Please file it with bugzilla.


Sure I will do that as I think it is impossible without a deep cast. But, I don't know that it is an implementation bug as much as a incorrect definition of the foreach per the langauge spec.

From 'Foreach over Associative Arrays':

"The type of the variable must match the type of the array contents. If there are two variables declared, the first is said to be the index and the second is said to be the value. The index must be of the same type as the indexing type of the associative array. It cannot be ref, and it is set to be the index of the array element."

I do not understand why "it cannot be ref" and am suggesting that that should say and be implemented as rather: "it is naturally a ref, whether you include the ref keyword or not and in fact it is ref const(K). This way we could do:

foreach(k, ref v; aa) { }

when aa is a const(V[K]).


Reply via email to