www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Eponymous Aggregates

reply "JS" <js.mdnq gmail.com> writes:
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
next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
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
prev sibling next sibling parent reply "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
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
parent Timon Gehr <timon.gehr gmx.ch> writes:
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
prev sibling next sibling parent "JS" <js.mdnq gmail.com> writes:
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.
Aug 10 2013
prev sibling parent "JS" <js.mdnq gmail.com> writes:
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!
Aug 10 2013