[Article Submission] Have Your Efficiency, and Flexibility Too

Nick Sabalausky a at a.a
Tue May 31 15:22:26 PDT 2011


"Timon Gehr" <timon.gehr at gmx.ch> wrote in message 
news:is2lts$2fcn$1 at digitalmars.com...
>
> @Article: A very good read, it does not get boring even though it is quite 
> long. I
> like it.
>

Thanks :)

> Small nitpick:
> mixin(declareInterface("IGizmo", "Gizmo!(numPorts, isSpinnable)"));
>
> It seems like this should be a mixin template, not a string mixin. Also 
> you
> wouldn't normally want to specify ThisType. Use typeof(this):
>
> mixin template declareInterface(string interfaceName){
>    mixin(`enum _this_implements_interface_`~interfaceName~`=true;`);
>    mixin(`static assert(
>               is`~interfaceName~`!(typeof(this)),
>
>               "This type fails to implement `~interfaceName~`"
>           );`
>    );
> }
>
> and then you do just:
> mixin declareInterface!"IGizmo";
>

I like the idea, but I just tried it and when I do that, 'isIGizmo' doesn't 
seem to be able to find the '_this_implements_interface_IGizmo' (using DMD 
2.053). But, I wonder if that approach might be getting a little too fancy 
for this anyway. That would definitely be the right way to go for a real 
library, but for the article, the simpler it is to understand how it works, 
the better, and putting string mixins inside a template mixin is more to 
understand than just a string mixin (of course, I'm using CTFE too, but 
that's probably conceptually simpler for most people than template mixins).





More information about the Digitalmars-d mailing list