Convert call to a string
H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Feb 15 14:18:48 PST 2017
On Wed, Feb 15, 2017 at 10:07:22PM +0000, data pulverizer via Digitalmars-d-learn wrote:
> I'd like to convert a call to a string for debug printing purposes for
> example:
>
>
> ```
> import std.stdio : writeln;
> void someFunction(int x, string y){}
> string myCall = debugPrint(someFunction(1, "hello"));
> writeln(myCall);
> ```
> writes:
> someFunction(1, "hello")
>
>
> Does this functionality exists? If not how can I construct it? Please
> note that the call `someFunction(1, "hello")` should also be executed.
[...]
Try this:
auto debugPrint(string expr)() {
writeln(expr);
return mixin(expr);
}
string myCall = debugPrint!`someFunction(1, "hello")`;
T
--
Klein bottle for rent ... inquire within. -- Stephen Mulraney
More information about the Digitalmars-d-learn
mailing list