plans for macros
Simen Kjaeraas
simen.kjaras at gmail.com
Wed May 14 10:21:21 PDT 2008
BCS <ao at pathlink.com> wrote:
> Reply to Steven,
>
>> If I have a log object, and that log object is supposed to evaluate
>> its arguments only if the logging level allows it, checked at runtime.
>>
>
> as a bit of an aside: this can be done using lazy
>
>
> void Log(uint level)(lazy char[] str)
> {
> if(current > level) RealLog.output(str());
> }
>
> alias Log!(Critical) CriticalLog;
> ...
> alias Log!(Debug) DebugLog;
Like the man said:
Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> But D has a better way:
> class Log
> {
> void outputInformation(lazy string x)
> {
> if(isEnabledAtLevel(Information))
> output(x);
> }
> }
It should (theoretically, at least) be possible for the compiler to inline
the log function and the delegate, thus doing exactly what Steven asks.
-- Simen
More information about the Digitalmars-d-learn
mailing list