std.logger

Johannes Pfau nospam at example.com
Fri Aug 23 15:29:21 PDT 2013


Am Fri, 23 Aug 2013 16:08:40 -0400
schrieb "Jonathan M Davis" <jmdavisProg at gmx.com>:

> On Friday, August 23, 2013 21:47:44 Johannes Pfau wrote:
> > Am Fri, 23 Aug 2013 15:16:05 -0400
> > 
> > schrieb "Jonathan M Davis" <jmdavisProg at gmx.com>:
> > > On Friday, August 23, 2013 19:21:33 Gary Willoughby wrote:
> > > > I don't think you can bloat a simple logger too much with
> > > > templates. It's a pretty simple framework.
> > > 
> > > If __FILE__ and __LINE__ are template arguments to a logging
> > > function rather than function arguments (and you can't make
> > > __FILE__ and __LINE__ default function arguments if the function
> > > is variadic as it would have to be to support format strings),
> > > then you get a new template instantation every single time that
> > > you call the function, unless you call it more than once on the
> > > same line (which you're unlikely to ever do).
> > > 
> > > I want to think that there's a way to handle this if you get
> > > clever, but I can't think of a clever way to get around the
> > > problem at the moment.
> > > 
> > > - Jonathan M Davis
> > 
> > Make the templated function a stub which redirects to a function
> > which uses normal function arguments and rely on inlining?
> 
> Inlining will have no effect on __FILE__ and __LINE__, and it would
> be a bug if it did, because they're supposed to give the file and
> line number of the source code, whereas inlining only affects the
> generated binary.

I think you misunderstood. If you write code like this:

void log(string file = __FILE__)() //A template
{
    logImpl(file);
}
void logImpl(string file){} //Not a template

The compiler can always inline the log template. So there's no
template bloat as there will be effectively no instances of log.
Instead it will be inlined and logImpl will be called directly just as
if you manually called logImpl(__FILE__).


More information about the Digitalmars-d mailing list