Re: Why can't I assign a mixin to an alias?
On Friday, 10 June 2016 at 22:38:29 UTC, Dechcaudron wrote: I have the following code: private string getVariableSignalWrappersName(VarType)() { return VarType.stringof ~ "SignalWrappers"; } void addVariableListener(VarType)(int variableIndex, void delegate(int, VarType)) { alias typeSignalWrappers = mixin(getVariableSignalWrappersName!VarType); } On compilation, the following error is issued: Error: basic type expected, not mixin Why should it be like that? I believe the compiler should not impose restrictions on what mixins can or cannot do :/ I'm no expert, but this looks like a grammar issue more than anything else. You can work around it by moving the alias declaration into the mixin. mixin("alias typeSignalWrappers = " ~ getVariableSignalWrappersName!VarType ~ ";");
Re: Is it possible to use a template to choose between foreach and foreach_reverse?
On Saturday, 4 June 2016 at 14:32:23 UTC, pineapple wrote: It would be fantastic if I could write this - static if(forward){ foreach(item; items) dostuff(); }else{ foreach_reverse(item; items) dostuff(); } as something like this - foreach!forward(item; items) dostuff(); Is there any way to accomplish this? As far as I recall, foreach_reverse is deprecated in favour of range operations. ie. import std.algorithm, std.range; static if(forward) { items.each!(item => doStuff()); } else { items.retro.each!(item => doStuff()); } As for your question, I suggest writing a range function that calls retro conditionally. Something like, items.direction!(forward).each!(item => doStuff());