string mixin and alias
Jesse Phillips via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jul 29 11:39:23 PDT 2016
On Friday, 29 July 2016 at 18:34:56 UTC, Jesse Phillips wrote:
> Here the generateCode() is mixed in to the context of foo(),
> which is fine if your code is performing actions but is no good
> if you're creating declarations that you want to use in the
> context of main().
Here is a fully functioning example:
-----------
string generateCode(string s){return s;}
void main()
{
int a, b;
enum s = "a = 2 + 3; b = 4 + a;";
foo!(s)(a, b);
assert(a == 5);
assert(b == 9);
}
void foo(alias s)(ref int a, ref int b) {
mixin(generateCode(s));
}
-----------
More information about the Digitalmars-d-learn
mailing list