How to create a function that behaves like std.stdio.writeln but prepends output with __FILE__:_LINE_

WebFreak001 d.forum at webfreak.org
Tue Jan 25 12:31:36 UTC 2022


On Tuesday, 25 January 2022 at 12:27:16 UTC, Dennis wrote:
> On Tuesday, 25 January 2022 at 12:11:01 UTC, JG wrote:
>> Any ideas how one can achieve what is written in the subject 
>> line?
>
> ```D
> void f(T...)(auto ref T args, string file = __FILE__, int line 
> = __LINE__)
> {
>     writeln(file, ":", line, ": ", args);
> }
> ```

note: default arguments after variadic arguments are supported 
since D 2.079.0: 
https://dlang.org/changelog/2.079.0.html#default_after_variadic


More information about the Digitalmars-d-learn mailing list