mixin extension

Matthias Spycher matthias at coware.com
Wed May 3 12:04:19 PDT 2006


Here's an idea to extend mixins in a manner that would allow you to mix 
code around a block in D.

If you had:

template Trace(f:char[])
{
   printf("Entering %s", f);
}
{
   printf("Exiting %s", f);
}

Note the two blocks associated with a single template declaration. You 
might mix code around a third block with:

void test()
{
   mixin Trace!("test") {
     do_something();
     more_here();
   }
}

resulting in the equivalent of:

void test()
{
   printf("Entering %s", f);
   do_something();
   more_here();
   printf("Exiting %s", f);
}

Ideally, such a construct could be used in conjunction with a 
conditional version statement:

void test()
{
   version (Log) mixin Trace!("test") {
     do_something();
     more_here();
   }
}

which when logging is disabled would evaluate to:

void test()
{
   do_something();
   more_here();
}

Is this feasible? Are there better ways?

Matthias



More information about the Digitalmars-d mailing list