Thread overview | |||||
---|---|---|---|---|---|
|
May 23, 2004 Request with mixins | ||||
---|---|---|---|---|
| ||||
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 23, 2004 Re: Request with mixins | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | 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 23, 2004 Re: Request with mixins | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | 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() {..} > } > |
Copyright © 1999-2021 by the D Language Foundation