I have a question. In my code I want to make uniform template function to call JSON RPC methods (that are regular D functions of any type). So I need some way to call this function with no function params and with them in the same manner. There is a concrete example, because this description isn't obvious (I think that)

//----------------
import std.stdio, std.json, std.conv, std.traits;


JSONValue getStdJSON(T)(T dValue)
{
        static if( is( T == void ) )
        {       
                JSONValue result;
                result.type = JSON_Type.NULL;
                return result;
        }
        else
        {
                //....
        }
        
}

void f()
{
        writeln("Hello!!");   
}

void main()
{
        writeln(getStdJSON(f()));
}
//------------------
Compilation output:
/d661/f210.d(28): Error: template f210.getStdJSON does not match any function template declaration. Candidates are:
/d661/f210.d(6):        f210.getStdJSON(T)(T dValue)
/d661/f210.d(28): Error: template f210.getStdJSON(T)(T dValue) cannot deduce template function from argument types !()(void)

//---------------

So my question is how can I implement something like this? Problem is that we don't really have value of type void, but I want uniform way to call this function when it has parameter with concrete type and not.

Reply via email to