DIP 1022--foreach auto ref--Community Review Round 1

Nick Treleaven nick at geany.org
Sun Aug 11 14:52:08 UTC 2019


On Saturday, 10 August 2019 at 21:42:00 UTC, Manu wrote:
>   static foreach (ref i; [10, 20, 30])
>       pragma(msg, __traits(isRef, i));
>
>> true true true
>
> As above, we could allow this by creating temporaries the same 
> as function arguments... but we've decided not to allow ref 
> iterators from rvalues.

It doesn't need temporaries, [2][0] is an lvalue with existing 
dmd:

void f(ref int i);
void main(){
     f([2][0]); //compiles
}

> TL;DR, your sentence "It should be allowed in static foreach, 
> but with no effect" should be removed, and if you want to 
> detail the expected semantics with `static foreach`, that might 
> be a good idea.

+1


More information about the Digitalmars-d mailing list