Convert call to a string
H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Feb 15 14:34:22 PST 2017
On Wed, Feb 15, 2017 at 02:18:48PM -0800, H. S. Teoh via Digitalmars-d-learn wrote:
[...]
> Try this:
>
> auto debugPrint(string expr)() {
> writeln(expr);
> return mixin(expr);
> }
>
> string myCall = debugPrint!`someFunction(1, "hello")`;
[...]
OTOH, that won't work with local variables (it'd only print the variable
names, not the values). Presumably you'd also want to print the
variables too. So perhaps something like this instead:
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);
T
--
I see that you JS got Bach.
More information about the Digitalmars-d-learn
mailing list