On Wednesday, 15 February 2017 at 22:34:22 UTC, H. S. Teoh wrote:
auto debugPrint(alias fun, A...)(A args) {
writefln("%s(%(%s, %))", __traits(identifier, fun), [args]);
return fun(args);
}
string arg = "hello";
string myCall = debugPrint!someFunction(1, arg);
`[args]` doesn't work when the tuple elements don't have a common
type. But you can pass `args` as is to writefln and generate the
format string accordingly:
----
import std.range: repeat;
import std.string: join;
immutable string argsfmt = "%s".repeat(args.length).join(", ");
writefln("%s(" ~ argsfmt ~ ")", __traits(identifier, fun), args);
----