May 18, 2004 Proposal for alias extension | ||||
|---|---|---|---|---|
| ||||
It occurs to me that it would be extremely powerful to be able to do something like:
alias SomeClass.* *;
and pull in all the methods of that class into the current scope. Uses for this:
Proxy classes
class Proxy(T)
{
...
alias T.* *;
}
More powerful mixins:
template Foo(T)
{
alias T.* *;
}
class Mixed
{
SomeClass X;
mixin Foo!(X);
this() { X = new SomeClass; }
}
Of course, it would be even simpler and more powerful if mixins had constructors... But that rant is already somewhere ;)
I know this approaches the "accidental inclusion of a compile-time functional language", but this would be incredibly powerful. One thought that comes to mind: this probably should not pull in operator overloads and such, only regular methods.
Thoughts?
Mike Swieton
__
It's kind of fun to do the impossible.
- Walt Disney
| ||||
May 18, 2004 Re: Proposal for alias extension | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Mike Swieton | isn't that what mixins are made for now? (http://www.digitalmars.com/d/mixin.html) In article <pan.2004.05.18.14.59.46.445402@swieton.net>, Mike Swieton says... > >It occurs to me that it would be extremely powerful to be able to do something like: > >alias SomeClass.* *; > >and pull in all the methods of that class into the current scope. Uses for this: > >Proxy classes > >class Proxy(T) >{ > ... > alias T.* *; >} > >More powerful mixins: > >template Foo(T) >{ > alias T.* *; >} > >class Mixed >{ > SomeClass X; > mixin Foo!(X); > this() { X = new SomeClass; } >} > >Of course, it would be even simpler and more powerful if mixins had constructors... But that rant is already somewhere ;) > >I know this approaches the "accidental inclusion of a compile-time functional language", but this would be incredibly powerful. One thought that comes to mind: this probably should not pull in operator overloads and such, only regular methods. > >Thoughts? > >Mike Swieton >__ >It's kind of fun to do the impossible. > - Walt Disney > | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply