foreach and filter

Jakob Ovrum jakobovrum at gmail.com
Wed Apr 11 10:09:11 PDT 2012


On Wednesday, 11 April 2012 at 17:00:43 UTC, bearophile wrote:
> Jakob Ovrum:
>
>> Value types with no indirection are implicitly convertible to 
>> immutable.
>>
>> -----------
>> void main()
>> {
>>    int a = 2;
>>    immutable int b = a;
>> }
>> -----------
>
> And far more, even with immutable reference types, in this 
> program 'a' has to be immutable, no just const:
>
>
> -snip-

I mentioned this as a side-note in my other reply in the thread. 
It's a truly neat feature which I feel has much potential, I hope 
to see some compelling use-cases with standard library functions 
in the future as Phobos becomes more pure-correct.

If the parameter to `array` in the original problem had presented 
a pure interface, he should have been able to get an immutable 
result like he tried initially thanks to this feature and pure 
inference, which is exciting to think about.

Of course, it's useless in this particular case as his parameter 
to `array` cannot have a pure interface (it's lazily evaluated, 
right?), and secondly, an immutable range is not usable with 
foreach.


More information about the Digitalmars-d mailing list