| Thread overview | |||||
|---|---|---|---|---|---|
|
April 03, 2007 interface.tupleof proposal | ||||
|---|---|---|---|---|
| ||||
I would really like to be able to do something like this
|class Foo(T) : T
|{
| static assert(T : interface)
| foreach(method; T.tupleof)
| {
| method.return method(method.args arg)
| {
| // implement based on type and args of method
| }
| }
|}
This would allow for some cool things like a fully template version of my interface-over-network code-generator. Another things would be a dynamic interface inheritance
|class DnyInterface(T, V...) : T
|{
| private T t;
| this(T t_){t = t_;}
|
| static assert(T : interface)
| foreach(method; T.tupleof)
| {
| method.return method(method.args arg)
| {
| return t.method(arg)
| }
| }
|}
class Use : DnyInterface!(I) {}
What exactly this would be used for I don't know, but one thought is that an interface returned from a dll/so could now be "inherited from" by a class in the loading program.
| ||||
April 05, 2007 Re: interface.tupleof proposal | ||||
|---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS schrieb:
> I would really like to be able to do something like this
>
> |class Foo(T) : T
> |{
> | static assert(T : interface)
> | foreach(method; T.tupleof)
> | {
> | method.return method(method.args arg)
> | {
> | // implement based on type and args of method
> | }
> | }
> |}
>
> This would allow for some cool things like a fully template version of my interface-over-network code-generator. Another things would be a dynamic interface inheritance
>
>
> |class DnyInterface(T, V...) : T
> |{
> | private T t;
> | this(T t_){t = t_;}
> |
> | static assert(T : interface)
> | foreach(method; T.tupleof)
> | {
> | method.return method(method.args arg)
> | {
> | return t.method(arg)
> | }
> | }
> |}
>
> class Use : DnyInterface!(I) {}
>
> What exactly this would be used for I don't know, but one thought is that an interface returned from a dll/so could now be "inherited from" by a class in the loading program.
>
>
that is something that im waiting for - but it seems that no one is interessed in such an compile-time reflectin stuff.. i would be also nice to walk through the oop hierachie (for typed factories or something)
| |||
April 05, 2007 Re: interface.tupleof proposal | ||||
|---|---|---|---|---|
| ||||
Posted in reply to dennis luehring | dennis luehring Wrote:
> that is something that im waiting for - but it seems that no one is interessed in such an compile-time reflectin stuff.. i would be also nice to walk through the oop hierachie (for typed factories or something)
For now, I'd say don't use classes. Use AA's, or arrays of unions?
Walter and friends *are* interested in compile-time reflection. Look up their talks about reflecting the AST.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply