immutable ref foreach on values

Dmitry Olshansky dmitry.olsh at gmail.com
Fri Jun 22 05:28:24 PDT 2012


On 22-Jun-12 16:16, bearophile wrote:
> Tobias Pankrath:
>
>> 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.
>
> But aren't int implicitly castable to immutable?
>

then every array is implicitly castable to tail immutable.
int[] array = [1, 2];

     foreach (ref immutable(int) x; array) {
	...
	func(arr); // arr is mutable, thus func can change x
	// so x can be at most  const
     }

-- 
Dmitry Olshansky




More information about the Digitalmars-d-learn mailing list