On Sunday, 30 November 2014 at 08:00:20 UTC, Daniel Kozak wrote:
On Sunday, 30 November 2014 at 02:10:13 UTC, bitwise wrote:
In the following program, the output does not contain
"SomeClass". Is this a bug?
Maybe yes, as a workaround this works:
module main;
import std.stdio;
template Test()
{
enum Test = q{
class SomeClass {
int n = 123;
}
};
}
mixin(Test!());
void main() {
auto sc = new SomeClass;
writeln(sc.n);
foreach(m; ModuleInfo)
{
foreach(c; m.localClasses())
{
writeln(c.name);
}
}
}
Btw. you can use just template, IIRC there is no difference
between template and mixin template
Hey, thanks for the q{} trick. I knew I had seen it somewhere...
but couldn't find it.
That trick only really helps when there is minimal concatenation
going on though. When you have to splice a bunch of stuff
together, a TokenString doesn't provide much relief.
Docs for template mixins explicitly support the behaviour that
I'm after, so I'm gonna file a bug.
" TemplateMixin takes an arbitrary set of declarations from the
body of a TemplateDeclaration and inserts them into the current
context."