digitalmars.D - Eponymous Aggregates
- JS (8/8) Aug 10 2013 e.g.,
- Andrej Mitrovic (4/11) Aug 10 2013 interface A(T)
- Simen Kjaeraas (23/31) Aug 10 2013 Tried with DMD 2.063.2, and I'm unable to make A!T compile. Are you sure
- JS (24/58) Aug 10 2013 No, the code does not compile as it is a proposal.
- Timon Gehr (2/5) Aug 10 2013 http://i.imgur.com/u29r8pH.jpg
- JS (2/9) Aug 10 2013 Too bad for you... I already did a few days ago!
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.
Aug 10 2013
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) { }
Aug 10 2013
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; }
Aug 10 2013
On Saturday, 10 August 2013 at 18:28:41 UTC, Simen Kjaeraas wrote:On 2013-08-10, 14:58, JS wrote: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.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; }
Aug 10 2013
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
Aug 10 2013
On Saturday, 10 August 2013 at 22:17:11 UTC, Timon Gehr wrote:On 08/10/2013 10:10 PM, JS wrote:Too bad for you... I already did a few days ago!... This is simply generalizing eponymous templates to interfaces, classes, structs, etc.http://i.imgur.com/u29r8pH.jpg
Aug 10 2013