digitalmars.D - Request with mixins
- J Anderson (27/27) May 22 2004 I would like to be able to do something like this:
- J Anderson (5/30) May 22 2004 Of course "this" doesn't exist for static object, however the static
- Norbert Nemec (15/55) May 23 2004 I fully second that proposal.
I would like to be able to do something like this: template A(T) { } class C { mixin A!(typeof(this)); } or parhaps: template A(T) { } class C { mixin A!(this); } Which would be the same as: template A(T) { } class C { mixin A!(C); } It's just about making code more generic. It could also be used within mixins, so you would have no need to pass the class name by parameter: template C() { typeof(this) getType() {..} } -- -Anderson: http://badmama.com.au/~anderson/
May 22 2004
Of course "this" doesn't exist for static object, however the static type name could be called something else like "me". J Anderson wrote:I would like to be able to do something like this: template A(T) { } class C { mixin A!(typeof(this)); } or parhaps: template A(T) { } class C { mixin A!(this); } Which would be the same as: template A(T) { } class C { mixin A!(C); } It's just about making code more generic. It could also be used within mixins, so you would have no need to pass the class name by parameter: template C() { typeof(this) getType() {..} }-- -Anderson: http://badmama.com.au/~anderson/
May 22 2004
I fully second that proposal. Even though "this" only exists within non-static functions, "typeof(this)" should definitely be allowed in the whole class. B.t.w: This is again an idea from Sather. D-mixins are similar to inclusion of classes, so a special type "SAME" is defined, which is always replaced by the type of the including class. This would even allow stuff like: ------------------------------- template LinkedList { typeof(this) next; } class Node { mixin LinkedList; } ------------------------------- J Anderson wrote:I would like to be able to do something like this: template A(T) { } class C { mixin A!(typeof(this)); } or parhaps: template A(T) { } class C { mixin A!(this); } Which would be the same as: template A(T) { } class C { mixin A!(C); } It's just about making code more generic. It could also be used within mixins, so you would have no need to pass the class name by parameter: template C() { typeof(this) getType() {..} }
May 23 2004