immutable ref foreach on values
Tobias Pankrath
tobias at pankrath.net
Fri Jun 22 05:05:49 PDT 2012
On Friday, 22 June 2012 at 11:07:14 UTC, bearophile wrote:
> Is this expected and good?
>
>
> void main() {
> int[] array = [1, 2];
> foreach (ref const(int) x; array) {} // OK
> foreach (ref immutable(int) x; array) {} // error
> }
>
>
> DMD 2.060alpha:
> temp.d(4): Error: argument type mismatch, int to ref
> immutable(int)
>
> Thank you,
> bye,
> bearophile
I think it's good. In this special case, the compiler can see
that you can't change array behind his back. That seems not to be
true in general.
More information about the Digitalmars-d-learn
mailing list