hidden passing of __FILE__ and __LINE__ into function

Stanislav Blinov via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 18 06:48:57 PDT 2017


On Tuesday, 18 April 2017 at 13:28:06 UTC, Solomon E wrote:

> I tried to produce an example of calling a function with
> variadic template arguments using special tokens __FILE__ and 
> __LINE__.
>
> This compiles and runs, producing the output shown, using the 
> default gdc
> provided by Ubuntu 17.04. This appears to be a workaround for 
> Issue 8687...

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



More information about the Digitalmars-d-learn mailing list