Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
August 10, 2013 Eponymous Aggregates | ||||
---|---|---|---|---|
| ||||
e.g., interface A { static T A(T)() { ... } } can be used as A!T instead of A.A!T. Same for classes and structs. If you want a use case I'm not going to stop you from coming up with one... so feel free. |
August 10, 2013 Re: Eponymous Aggregates | ||||
---|---|---|---|---|
| ||||
Posted in reply to JS | On 8/10/13, JS <js.mdnq@gmail.com> wrote:
> e.g.,
>
> interface A
> {
> static T A(T)() { ... }
> }
>
> can be used as A!T instead of A.A!T. Same for classes and structs.
interface A(T)
{
}
|
August 10, 2013 Re: Eponymous Aggregates | ||||
---|---|---|---|---|
| ||||
Posted in reply to JS | On 2013-08-10, 14:58, JS wrote:
> e.g.,
>
> interface A
> {
> static T A(T)() { ... }
> }
>
> can be used as A!T instead of A.A!T. Same for classes and structs. If you want a use case I'm not going to stop you from coming up with one... so feel free.
Tried with DMD 2.063.2, and I'm unable to make A!T compile. Are you sure
you've written the code you intended to?
For reference, this is the code I tried:
interface A {
static T A(T)() {
return T.init;
}
}
void main() {
A!int a; // Error: template instance A!(int) A is not a template declaration, it is a interface
auto b = A!int; // Error: template instance A!(int) A is not a template declaration, it is a interface
}
This code, of course, works:
template A(T) {
interface A {
}
}
void main() {
A!int a;
}
|
August 10, 2013 Re: Eponymous Aggregates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjaeraas | On Saturday, 10 August 2013 at 18:28:41 UTC, Simen Kjaeraas wrote:
> On 2013-08-10, 14:58, JS wrote:
>
>> e.g.,
>>
>> interface A
>> {
>> static T A(T)() { ... }
>> }
>>
>> can be used as A!T instead of A.A!T. Same for classes and structs. If you want a use case I'm not going to stop you from coming up with one... so feel free.
>
> Tried with DMD 2.063.2, and I'm unable to make A!T compile. Are you sure
> you've written the code you intended to?
>
> For reference, this is the code I tried:
>
> interface A {
> static T A(T)() {
> return T.init;
> }
> }
>
> void main() {
> A!int a; // Error: template instance A!(int) A is not a template declaration, it is a interface
> auto b = A!int; // Error: template instance A!(int) A is not a template declaration, it is a interface
> }
>
> This code, of course, works:
>
> template A(T) {
> interface A {
> }
> }
>
> void main() {
> A!int a;
> }
No, the code does not compile as it is a proposal.
The issue is simple to allow interfaces to have Eponymous static members. This makes it easier to use in some cases. Your template example just creates a template... but does nothing as far as inheritance.
interface iFactory(A)
{
static A iFactory(Args...)(Args args) { return new A; }
// ....
}
class Q : iFactory!Q
{
// ....
}
auto q = iFactory!Q();
instead of
auto q = iFactory!Q.iFactory();
or
auto q = Q.iFactory()
The last case being only acceptable if Q inherits from iFactory(which it may not).
This is simply generalizing eponymous templates to interfaces, classes, structs, etc.
|
August 10, 2013 Re: Eponymous Aggregates | ||||
---|---|---|---|---|
| ||||
Posted in reply to JS | On 08/10/2013 10:10 PM, JS wrote: > ... > This is simply generalizing eponymous templates to interfaces, classes, > structs, etc. > http://i.imgur.com/u29r8pH.jpg |
August 11, 2013 Re: Eponymous Aggregates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On Saturday, 10 August 2013 at 22:17:11 UTC, Timon Gehr wrote:
> On 08/10/2013 10:10 PM, JS wrote:
>> ...
>> This is simply generalizing eponymous templates to interfaces, classes,
>> structs, etc.
>>
>
> http://i.imgur.com/u29r8pH.jpg
Too bad for you... I already did a few days ago!
|
Copyright © 1999-2021 by the D Language Foundation