D mixins

Waldemar waldemar at wa-ba.com
Thu Jan 4 20:39:06 PST 2007


== Quote from Chris Nicholson-Sauls (ibisbasenji at gmail.com)'s article
> mike wrote:
> > Am 05.01.2007, 00:19 Uhr, schrieb Waldemar <waldemar at wa-ba.com>:
> >
> >>> >> Well coming from C++ this would not make much sense.  Where would you
> >>> >> use them in C++?  Where would you use them in D?  Are there any
> >>> good D
> >>> >> examples that show the power of mixins in a simple way that would be
> >>> >> more ugly another way?
> >>
> >> Roughly speaking, anytime you see a multiline #define macro in C++
> >> (especially
> >> with parameters), you would use a mixin in D.
> >>
> >> That's only one sample use, but it should speak to the Cplusplusers.
> >>
> >
> > Erm ... I don't think you can insert this line via a mixin into a
> > certain scope:
> >
> > ' scope (failure) dosomething();
> >
> > But, please, tell me I'm wrong, I would really need that :)
> >
> > -mike
> >
> > --Erstellt mit Operas revolutionärem E-Mail-Modul:
> > http://www.opera.com/mail/
> Sadly, no, you cannot do that, because templates (perhaps mixins should be their
own type?
>   er, nevermind that) have their own evaluation scope, with the outer scope
"friended" in.
>   So, scope guards will execute on the templates's own scope rather than the
host's.  I've
> actually tried this, with my fingers crossed.  All to no avail.  (It would've
been a darn
> nifty way to do selective tracebacks.  But alas.)
> -- Chris Nicholson-Sauls

I was not aware of that, but the post was intended for C++ users.  Most, if not
all, C/C++ ugly macros can be nicely written as mixins in D.

Now, getting back to D, I suppose one could write the scope functionality "by
hand" (the "C++ way") into a mixin!  Inserting it would produce the desired
effect.  That's a theory at the moment, I do not have a code.




More information about the Digitalmars-d mailing list