On 5/19/2011 1:23 AM, Jesse Phillips wrote:
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();
}
Hi Jesse,
That is cool. Useful example like this should be within the
documentation also. That helped me a lot. Now, I do not have to be
concerned that the class level mixin usage class missed out the
inheritance and also the implementation.
This pattern is very useful for flattening the Object inheritance tree.
D is cool!!!
--
Matthew Ong
email: on...@yahoo.com