Any ideas for lazy evaluation on varaible argument functions?
Darryl B
darrylbleau at gmail.com
Fri Oct 19 09:40:09 PDT 2007
== Quote from Christopher Wright (dhasenan at gmail.com)'s article
> It can be done; just replace the current functions with structs equipped
> with opCall and format.
> private struct LogCaller {
> Level level;
> Logger opCall (string msg) {
> return append (level, msg);
> }
> void format (char[] buffer, char[] formatStr, ...) {
> level.format (buffer, formatStr, _arguments, _argptr);
> }
> static LogCaller opCall (Level level) {
> LogCaller caller;
> caller.level = level;
> return caller;
> }
> }
> The remainder of the work is a bit less than obvious. Maybe a template
> taking an alias parameter -- the code uses static fields on Logger to
> determine what to append to.
Ok, I think I sort of see where you're going here, but isn't this also going to
become non-thread safe (keeping state between calls?). I don't think it would be a
good idea to have to manage thread safety in the logging module. It would also be
optimal to not have to pass a buffer each time you want to do some output. :)
More information about the Digitalmars-d
mailing list