DIP 57: static foreach
Timon Gehr via Digitalmars-d
digitalmars-d at puremagic.com
Tue Nov 3 16:17:24 PST 2015
On 11/04/2015 12:39 AM, Daniel N wrote:
> On Wednesday, 26 March 2014 at 22:14:44 UTC, Timon Gehr wrote:
>> On 03/26/2014 01:33 PM, bearophile wrote:
>>> Timon Geh:
>>>
>>>> http://wiki.dlang.org/DIP57/
>>>>
>>>> Thoughts?
>>>
>>> Is it good to support this syntax too?
>>>
>>> static foreach (enum i; 0 .. 10) {}
>>>
>>> Bye,
>>> bearophile
>>
>> Yes, I think so.
>>
>> I'll try to finish the DIP this weekend.
>
> template DIP(Args...)
> {
> static foreach(alias a ; Args)
> {
> }
> }
>
> Would supporting 'alias' conflate too much into one DIP?
>
The DIP would allow:
template DIP(Args...){
static foreach(a;Args){}
}
This has the semantics you want.
This is identical to the existing Seq-foreach:
auto foo(Args...)(){
foreach(a;Args){
pragma(msg,a.stringof);
}
}
void main(){
foo!(1,"2",main,int)();
}
In this sense, the syntax seems redundant, but if it is introduced, it
should also be allowed for Seq-foreach. (I think this should also be the
case for enum loop variabes as proposed by bearophile.)
I have updated the DIP draft according to those considerations, but I'm
not sure whether 'alias' should be kept or not.
(Also, probably, using 'alias' or 'enum' on a loop variable for a
non-seq foreach should automatically turn it into a seq foreach, but I'm
not sure this is within the scope of the DIP.)
More information about the Digitalmars-d
mailing list