Can someone explain how mixin is implemented?
Jesse Phillips
jessekphillips+D at gmail.com
Wed May 18 10:23:11 PDT 2011
Matthew Ong Wrote:
> Perhaps I am missing something here. How can class level definition be
> part of the mixin?
>
> Does mixin generate the same binary code as #define as inline code,which
> meant that same binary is repeated everywhere that macro is used?
>
> Or does it make a linked to the in a centralized locations that allow
> binary sharing when it is the same typed T??
I can see what you're trying for and it looks like you'll need string mixins to make it happen.
Mixing is similar to #define in that it does string substitution, but it is unlike #define in that valid D is required declaration and call. You'll have to modify this with string mixins (I'm surprised it compiles excluding the non-existence of ClassB):
mixin template AType(alias T, U, alias V){class T : ClassC {
private:
U value;
public:
this(){}
void print(){}
mixin V;
}
}
class ClassC {}
mixin template btype() {
void someFunction() {};
}
mixin AType!("ClassB", string, btype);
void main() {
ClassC r = new ClassB();
}
More information about the Digitalmars-d-learn
mailing list