On Saturday, 17 November 2018 at 17:58:54 UTC, John Chapman wrote:
The following code doesn't compile because the generated type
name needs to be available inside the mixin's scope, whereas
it's actually in another module.
auto makeWith(string className, Args…)(auto ref Args args) {
mixin("return makeWith!(I", className, "Factory)(args);"); //
Fowarded to implementation of makeWith below
}
auto makeWith(T, Args…)(auto ref Args args) … // This is the
implementation
The idea is that users could type (for example)
makeWith!`Calendar`(…) instead of the longer
makeWith!ICalendarFactory(…).
I tried mixing in an import statement with the help of
std.traits.moduleName so that the I...Factory type would be
available but again the compiler complains that it's undefined.
Has anyone had a similar need and come up with a solution?
you need to qualify the names: I use
https://github.com/libmir/dcompute/blob/master/source/dcompute/driver/ocl/util.d#L77-L97
for this in dcompute (needs to be updated for the new style of
mixin but you get the idea).