A Perspective on D from game industry
Timon Gehr via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jun 17 07:59:01 PDT 2014
On 06/17/2014 03:36 PM, John Colvin wrote:
>>
>
> also, foreach that works outside of function scope would be awesome:
>
> mixin template A(TL ...)
> {
> foreach(i, T; TL)
> {
> mixin("T v" ~ i.to!string);
> }
> }
Also, identifier mixins might then somewhat clean up a lot of code. The
cases where a declaration name needs to be generated and this forces the
whole declaration to be written in awkward string interpolation style
are just too common, even more so if static foreach is supported (if
there is any named declaration inside the static foreach body at all and
the loop loops more than once, mixins will be required to prevent name
clashes.)
Eg:
mixin template A(T...){
static foreach(i,S;T){
S mixin(`v`~i.to!string);
auto mixin(`fun`~i.to!string)(S s){
// lots of code potentially using `i' without first
// converting it to a string only for it to be parsed back.
// ...
return s.mixin(`member`~i); // I've wanted this too
}
}
}
Also, there may be cases where one really wants to have local
declarations (eg. enums) inside the static foreach loop.
(I really need to get around to polishing/make formal that static
foreach DIP!)
More information about the Digitalmars-d
mailing list