How give a module to a CTFE function
arturg
var.spool.mail700 at gmail.com
Mon Mar 12 21:30:18 UTC 2018
On Monday, 12 March 2018 at 21:00:07 UTC, Xavier Bigand wrote:
> Hi,
>
> I have a CTFE function that I want to make more generic by
> given it a module as parameter.
>
>
> My actual code looks like :
>
> mixin(implementFunctionsOf());
>
>
> string implementFunctionsOf()
> {
> import std.traits;
>
> string res;
>
> foreach(name; __traits(allMembers, myHardCodedModule))
> {
> }
> return res;
> }
>
>
> I tried many things but I can't figure out the type of the
> parameter I should use for the function implementFunctionsOf.
you can use a alias or a string:
void fun(alias mod, string mod2)()
{
foreach(m; __traits(allMembers, mod))
pragma(msg, m);
foreach(m; __traits(allMembers, mixin(mod2)))
pragma(msg, m);
}
void main()
{
import std.stdio;
fun!(std.stdio, "std.stdio");
}
More information about the Digitalmars-d-learn
mailing list