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

2022-01-25 Thread JG via Digitalmars-d-learn

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);
}
```


Thank you very much.


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

2022-01-25 Thread WebFreak001 via Digitalmars-d-learn

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


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

2022-01-25 Thread Dennis via Digitalmars-d-learn

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);
}
```