std.logger

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Aug 23 13:08:44 PDT 2013


On Fri, Aug 23, 2013 at 03:16:05PM -0400, Jonathan M Davis wrote:
> 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.
[...]

Hmm. What about:

	void funcImpl(A...)(string file, int line, A args) { ... }
	template func(string file=__FILE__, int line=__LINE__, A...) {
		func(A args) { funcImpl(file, line, args); }
	}

It still has template bloat in that func will be instantiated for every
call though, but at least the function body isn't duplicated that many
times.


T

-- 
A program should be written to model the concepts of the task it
performs rather than the physical world or a process because this
maximizes the potential for it to be applied to tasks that are
conceptually similar and, more important, to tasks that have not yet
been conceived. -- Michael B. Allen


More information about the Digitalmars-d mailing list