www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Suggestion: auto templates

reply bobef <bobef lessequal.com> writes:
It would be nice if there were something like auto templates. I.e. if we 
have something like:

template mytemplate(_type)
{
	int foo(_type[] ar);
	int boo(_type ar);
}


and type something like

char[] a;
foo(a);
//or even
mytemplate.boo(a[0]);

DMD could autodetect the type and we won't need to specify the type 
every time manualy.
Feb 19 2006
next sibling parent reply Trevor Parscal <Trevor_member pathlink.com> writes:
In article <dt9fqs$1v1h$1 digitaldaemon.com>, bobef says...
It would be nice if there were something like auto templates. I.e. if we 
have something like:

template mytemplate(_type)
{
	int foo(_type[] ar);
	int boo(_type ar);
}


and type something like

char[] a;
foo(a);
//or even
mytemplate.boo(a[0]);

DMD could autodetect the type and we won't need to specify the type 
every time manualy.

This is a bit ambiguous in actual practice IMHO - but... I also can see how this would be awesome - when this ambiguity would be desired. Thanks, Trevor Parscal
Feb 19 2006
parent bobef <bobef lessequal.com> writes:
Trevor Parscal wrote:
 In article <dt9fqs$1v1h$1 digitaldaemon.com>, bobef says...
 It would be nice if there were something like auto templates. I.e. if we 
 have something like:

 template mytemplate(_type)
 {
 	int foo(_type[] ar);
 	int boo(_type ar);
 }


 and type something like

 char[] a;
 foo(a);
 //or even
 mytemplate.boo(a[0]);

 DMD could autodetect the type and we won't need to specify the type 
 every time manualy.

This is a bit ambiguous in actual practice IMHO - but... I also can see how this would be awesome - when this ambiguity would be desired. Thanks, Trevor Parscal

I mean the same way it is possible to write auto a=6;
Feb 19 2006
prev sibling parent reply Hasan Aljudy <hasan.aljudy gmail.com> writes:
bobef wrote:
 It would be nice if there were something like auto templates. I.e. if we 
 have something like:
 
 template mytemplate(_type)
 {
     int foo(_type[] ar);
     int boo(_type ar);
 }
 
 
 and type something like
 
 char[] a;
 foo(a);
 //or even
 mytemplate.boo(a[0]);
 
 DMD could autodetect the type and we won't need to specify the type 
 every time manualy.

is this the infamouse implicit template instantiation?
Feb 19 2006
next sibling parent reply bobef <bobef lessequal.com> writes:
Hasan Aljudy wrote:
 bobef wrote:
 It would be nice if there were something like auto templates. I.e. if 
 we have something like:

 template mytemplate(_type)
 {
     int foo(_type[] ar);
     int boo(_type ar);
 }


 and type something like

 char[] a;
 foo(a);
 //or even
 mytemplate.boo(a[0]);

 DMD could autodetect the type and we won't need to specify the type 
 every time manualy.

is this the infamouse implicit template instantiation?

I don't know.
Feb 19 2006
parent nick <nick.atamas gmail.com> writes:
It's a variation on it.

bobef wrote:
 Hasan Aljudy wrote:
 bobef wrote:
 It would be nice if there were something like auto templates. I.e. if
 we have something like:

 template mytemplate(_type)
 {
     int foo(_type[] ar);
     int boo(_type ar);
 }


 and type something like

 char[] a;
 foo(a);
 //or even
 mytemplate.boo(a[0]);

 DMD could autodetect the type and we won't need to specify the type
 every time manualy.

is this the infamouse implicit template instantiation?

I don't know.

Feb 19 2006
prev sibling parent Sean Kelly <sean f4.ca> writes:
Hasan Aljudy wrote:
 bobef wrote:
 It would be nice if there were something like auto templates. I.e. if 
 we have something like:

 template mytemplate(_type)
 {
     int foo(_type[] ar);
     int boo(_type ar);
 }


 and type something like

 char[] a;
 foo(a);
 //or even
 mytemplate.boo(a[0]);

 DMD could autodetect the type and we won't need to specify the type 
 every time manualy.

is this the infamouse implicit template instantiation?

Pretty much. Sean
Feb 19 2006