D mixins

Chris Nicholson-Sauls ibisbasenji at gmail.com
Thu Jan 4 19:28:09 PST 2007


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



More information about the Digitalmars-d mailing list