string mixin and alias

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 29 05:28:05 PDT 2016


On 7/29/16 2:38 AM, Andre Pany wrote:
> Hi,
>
> is there a way to alias a string mixin?
> Neither foo nor foo2 compiles.
>
> import std.meta : Alias;
> alias foo = (s) => Alias!(mixin(generateCode(s)));

s is a runtime parameter. You can't mixin stuff that is only available 
at runtime.

> alias foo2(string s) = Alias!(mixin(generateCode(s)));

This would work if the string is "main", let's say.

> string generateCode(string s){return "";}
>
> void main()
> {
>   enum s = "a = 2 + 3; b = 4 + a;";

This does not result in a symbol, an alias needs a symbol.

-Steve


More information about the Digitalmars-d-learn mailing list