change mixins
sybrandy
sybrandy at gmail.com
Mon Feb 15 07:32:30 PST 2010
On 02/15/2010 01:47 AM, BCS wrote:
> How were you doing it that the mixin keyword got in your way? I think
> the following should work right now:
>
> version(WithLogging) mixin Logging!(whatever);
>
> --
> <IXOYE><
>
>
That's actually the reverse of what I was doing. My template looked
something like this (And forgive me if I screw up the syntax...I don't
have the code in front of me):
template Trace(string msg)
{
version (NoLogging)
{
}
else
{
// Write to the log file...
}
}
And then in the code you'd see something like this:
mixin(Trace!("Msg..."));
My reason for this was to not have the user add all the version
statements throughout their code if they want to be able to compile a
version with no logging. In my design, I also have a normal class that
does the logging and the mixins are simply a wrapper around it.
As for why the mixin keyword is in the way, how much would you like
write the above line in your code? That's what I mean by being in the
way. To me, the following code would be more user-friendly:
mixin template Trace(string msg)
{
version (NoLogging)
{
}
else
{
// Write to the log file...
}
}
Trace!("Msg...");
Granted, it's not clear that a mixin is being used where you call Trace,
but I don't think it really matters too much.
Did I make that clear enough?
More information about the Digitalmars-d
mailing list