Convert call to a string
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Feb 15 14:58:42 PST 2017
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);
----
More information about the Digitalmars-d-learn
mailing list