foreach ref very broken: fails to call front(val)
monarch_dodra
monarch_dodra at gmail.com
Mon Jul 9 02:24:25 PDT 2012
On Monday, 2 July 2012 at 12:44:59 UTC, monarch_dodra wrote:
> ...
I opened this thread a week ago, and got little no feed back.
I've realized since:
1) "map" was a bad example, since it actually returns a new range
(does not modify the underlying values), so the output was normal
2) I pasted the wrong code, I forgot to put a "ref" in there, so
the output was normal.
Now take this example:
----
import std.stdio;
import std.algorithm;
import std.container;
void main()
{
Array!int arr = Array!int(1, 2, 3, 4, 5);
foreach(ref a; arr[])
{
a = 10;
}
writeln("Output: ", arr[]);
}
----
Output: [1, 2, 3, 4, 5]
----
I realize I'm still new to D, but I'd appreciate if somebody told
me if I am wrong(or being stupid).
Anyways, I'm bothered by several things:
Quoteth "The D programing language", 12.9.1: "If you specify ref
with value, the compiler replaces all uses of value with calls to
__c.front throughout the body of the loop".
Surely, there is something wrong here... right?
More information about the Digitalmars-d
mailing list