Making external types available to mixins

Kagamin spam at here.lot
Fri Nov 23 21:49:55 UTC 2018


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(…).

Well, just have all factories in one module and import it, then 
they will be visible.

import allfactories;
auto makeWith(string className, Args…)(auto ref Args args) {
   mixin("return makeWith!(I", className, "Factory)(args);"); // 
Fowarded to implementation of makeWith below
}

Or predeclare make functions in factory modules

interface ICalendarFactory
{
   ...
}

alias makeCalendar=makeWith!ICalendarFactory;


More information about the Digitalmars-d-learn mailing list