DIP 1010--Static foreach--Formal Review

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 11 00:42:22 PDT 2017


On 10.07.2017 20:07, jmh530 wrote:
> On Monday, 10 July 2017 at 08:53:42 UTC, Mike Parker wrote:
>> As promised, since there has been zero feedback on DIP 1010, "Static 
>> foreach", in either the Draft or Preliminary review rounds, I'm going 
>> to skip the normal two-week feedback cycle on the Formal review. If 
>> there are no major criticisms or objections raised in this thread, 
>> then sometime on Thursday of this week I'll send Walter & Andrei an 
>> email kicking off the decision process.
>>
>> So, if you have any thoughts on the DIP, now is the time to express them.
>>
>> Thanks!
>>
>> https://github.com/dlang/DIPs/blob/master/DIPs/DIP1010.md
> 
> I have two somewhat related questions.
> 
> In the "Generating fields" section, does it have to be a static struct? 

No. (They are static structs because they are static structs in 
Vladimir's code.)

> I see another example with an abstract class with a static for each, but 
> I don't see simpler struct/class examples.
> 
> I ask this because it seems like static foreach can be used to provide 
> the same functionality as inout, e.g.
> 
> class Foo
> {
>      static foreach(T; AliasSeq!(int,const(int),immutable(int)))
>      {
>          void bar(T t)
>          {
>          }
>      }
> }
> 
> 

Yes, this code works and does what you want. (The difference to inout is 
that you actually get three different implementations and you are able 
to vary the implementation based on T.)


More information about the Digitalmars-d mailing list