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

Manu turkeyman at gmail.com
Mon Aug 12 00:44:52 UTC 2019


On Sun, Aug 11, 2019 at 7:55 AM Nick Treleaven via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> 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
> }

Oh yeah... I forgot about that. Caused me so much trouble over the years.
So bad!

> > 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