Capturing __FILE__ and __LINE in a variadic templated function

Nordlöw via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Nov 1 14:40:10 PST 2015


Is it possible to make the following definition

void show(alias T, string file = __FILE__, uint line = __LINE__, 
string fun = __FUNCTION__)()
{
     import std.stdio: writeln;
     try { debug writeln(file, ":",line, ":" /* , ": in ",fun */, 
" debug: ", T.stringof, ":", T); }
     catch (Exception) { }
}

used as

unittest
{
     int x = 11;
     int y = 12;
     int z = 13;
     show!x;
     show!y;
     show!z;
}

variadic so that it, instead, can be called as

unittest
{
     int x = 11;
     int y = 12;
     int z = 13;
     show!(x,y,z);
}

and still capture current file, line and function?


More information about the Digitalmars-d-learn mailing list