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

JG someone at somewhere.com
Tue Jan 25 12:11:01 UTC 2022


Any ideas how one can achieve what is written in the subject line?

f below does achieve this but I one would expect that it produces
significant template bloat.

g achieves the aim but isn't very elegant.

     import std;
     void f(string file=__FILE__,size_t line=__LINE__,R...)(R r)
     {
       writeln(file,":",line," ",r);
     }
     void g(T)(T t,string file=__FILE__,size_t line=__LINE__)
     {
          writeln(file,":",line," ",t.expand);
     }

     void main()
     {
        f("hello ", 123);
        g(tuple("hello ",123));
     }


More information about the Digitalmars-d-learn mailing list