hidden passing of __FILE__ and __LINE__ into function

Dmitry via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 18 21:31:58 PDT 2017


On Tuesday, 18 April 2017 at 13:48:57 UTC, Stanislav Blinov wrote:
> There's a much more concise workaround, both in code written 
> and generated ;)
>
> import std.stdio;
>
> template func(string file = __FILE__, int line = __LINE__)
> {
>     auto func(T...)(auto ref T args)
>     {
>         writeln("called func with ", T.length, " args at ",
>                 file, ":", line);
>     }
> }
>
> void main()
> {
>     func();
>     func(1, 2, 3);
> }

Very nice. Thank you!


More information about the Digitalmars-d-learn mailing list