CT foreaches
monkyyy
crazymonkyyy at gmail.com
Fri Aug 1 13:51:43 UTC 2025
```d
import std;
void foo(int i:0)()=>"foo".writeln;
void foo(int i:1)()=>"bar".writeln;
void foo(int i:2)()=>"foobar".writeln;
void main(){
foreach(i,alias b; AliasSeq!("foo","bar")){
pragma(msg, b.stringof);
break;
}
pragma(msg,"---");
foreach(i,enum b; AliasSeq!("foo","bar")){
pragma(msg, b.stringof);
break;
}
pragma(msg,"---");
static foreach(i;0..3){
pragma(msg, i.stringof);
//break; //the scope error
}
pragma(msg,"---");
foreach(enum i;0..3){// ERROR ISNT CT. ISNT AN ENUM
pragma(msg, i.stringof);
//foo!i; //doesnt compile
break;
}
}
```
Theres bugs and unintended features here :D ; alias foreach is
undocumented even in the template book; the dip 1010 code block
that *may* be why this behavior exists doesnt actaully work, the
docs were wrong a week ago
etc. etc.
currently I believe:
a) static makes it a block, makes enum or alias infered
b) enum or alias of aliasSeq, whoever made thought there be an
upgrade to fully generalize the syntax
c) the dip 1010 section was ambiguous if it was real causing enum
to be ignored
anyone got any code blocks?
More information about the Digitalmars-d
mailing list