Auto-add static field when inherit // mixins, templates?
MarisaLovesUsAll via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Aug 21 12:58:16 PDT 2014
On Thursday, 21 August 2014 at 13:19:06 UTC, anonymous wrote:
>> 1) How to make mixin inject automatic?
>
> You could use this pattern:
>
> interface Component {}
> class ComponentImpl(T) {}
> class Sprite : ComponentImpl!Sprite {}
From my view, it's an architectural crutch. %)
> You can use `typeof(this)` in Manager:
>
> mixin template Manager()
> {
> void someMethod(typeof(this) otherInstance) {}
> }
Thanks, it works.
...I also have more questions %)
When I make mixin injection in one class, I want auto-injection
in another class. How can I do this?
class Component:GameObject
{
//second injection must be here and must be automatic
};
class Sprite:Component
{
mixin Manager; //first injection must activate second
injection by misterious way
};
mixin template Manager() {}
mixin template ComponentCaster(string type) {} //where 'type' is
a type obtained from Manager
//by typeof(this).stringof. As example, "Sprite".
...compile-time code generation is pain %) I think, it will be 50
times easier if we have built-in compiler script language. Or
just a library that will be able to execute code in compile time.
Sorry for Engrish.
Regards, Alex
More information about the Digitalmars-d-learn
mailing list