On Sunday, 1 July 2018 at 11:19:50 UTC, vino.B wrote:

Hi Timoses,

Thank you very much, can you help me on how to rewrite the below using Variadic template

Passing function as a parameter to another function:

void ptFun(T)(T function(string, string, int) coRoutine, Array!string Dirlst, ) { alias scRType = typeof(coRoutine(string.init, string.init, int.init));

where the "function(string, string, int) coRoutine" should be a variadic function

From,
Vino.B

I'm not sure, if get your question right, is this what you are looking for?


´´´
import std.stdio;
import std.traits;

void main()
{
        alias instantiation = ptFun!(size_t, fun!string);
        
        instantiation(4);

        alias instantiation2 = ptFun2!(fun!string);

        instantiation2(4);

}

auto fun(T...)(T input)
{
        return size_t(42);
}

void ptFun(T, alias funToCall)(size_t definedParam)
        if(is(T == ReturnType!(funToCall)))
{
        "ptFun called".writeln;
        assert(42 == funToCall("some string"));
}

void ptFun2(alias funToCall)(size_t definedParam)
        if(__traits(isSame, TemplateOf!(funToCall), fun))
{
        "ptFun2 called".writeln;
        assert(42 == funToCall("some string"));
}
´´´

Reply via email to