www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Template Tuple Defaults

reply Peter Neubauer <peterneubauer2 gmail.com> writes:
Is there a way to give default types to template tuple parameters?
Like this:


class Test (TTuple ... = [char, int] )
{
	// ...
}

void main ()
{
	Test t; // Equivalent to Test !(char, int) t;
}


Obviously, that does not compile.

Thanks in advance,
-Peter
Mar 29 2008
parent reply "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
On Sun, 30 Mar 2008 06:06:00 +0200, Peter Neubauer  =

<peterneubauer2 gmail.com> wrote:

 Is there a way to give default types to template tuple parameters?
 Like this:


 class Test (TTuple ... =3D [char, int] )
 {
 	// ...
 }

 void main ()
 {
 	Test t; // Equivalent to Test !(char, int) t;
 }


 Obviously, that does not compile.

 Thanks in advance,
 -Peter

This oughtta work (does on my confuser). import std.typetuple; class Test (TTuple ... =3D TypeTuple!(char, int) ) { // ... } void main () { Test t; // Equivalent to Test !(char, int) t; } -- Simen
Mar 30 2008
parent reply Peter Neubauer <peterneubauer2 gmail.com> writes:
Simen Kjaeraas schrieb:
 On Sun, 30 Mar 2008 06:06:00 +0200, Peter Neubauer 
 <peterneubauer2 gmail.com> wrote:
 
 Is there a way to give default types to template tuple parameters?
 Like this:


 class Test (TTuple ... = [char, int] )
 {
     // ...
 }

 void main ()
 {
     Test t; // Equivalent to Test !(char, int) t;
 }


 Obviously, that does not compile.

 Thanks in advance,
 -Peter

This oughtta work (does on my confuser). import std.typetuple; class Test (TTuple ... = TypeTuple!(char, int) ) { // ... } void main () { Test t; // Equivalent to Test !(char, int) t; } -- Simen

Strange, all I get is this: test.d(3): found '=' when expecting ')' test.d(3): { } expected following aggregate declaration test.d(3): no identifier for declarator TypeTuple!(char,int) test.d(3): semicolon expected, not ')' test.d(3): Declaration expected, not ')' Maybe this is a difference between D 1.0 and 2.0? (I'm using 1.0) -Peter
Mar 30 2008
parent "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
On Mon, 31 Mar 2008 01:29:10 +0200, Peter Neubauer  =

<peterneubauer2 gmail.com> wrote:

 Simen Kjaeraas schrieb:
 On Sun, 30 Mar 2008 06:06:00 +0200, Peter Neubauer  =


 <peterneubauer2 gmail.com> wrote:

 Is there a way to give default types to template tuple parameters?
 Like this:


 class Test (TTuple ... =3D [char, int] )
 {
     // ...
 }

 void main ()
 {
     Test t; // Equivalent to Test !(char, int) t;
 }


 Obviously, that does not compile.

 Thanks in advance,
 -Peter

import std.typetuple; class Test (TTuple ... =3D TypeTuple!(char, int) ) { // ... } void main () { Test t; // Equivalent to Test !(char, int) t; } -- Simen

Strange, all I get is this: test.d(3): found '=3D' when expecting ')' test.d(3): { } expected following aggregate declaration test.d(3): no identifier for declarator TypeTuple!(char,int) test.d(3): semicolon expected, not ')' test.d(3): Declaration expected, not ')' Maybe this is a difference between D 1.0 and 2.0? (I'm using 1.0) -Peter

Tested it again. Appears I did get part of it wrong. class test(TTuple =3D TypeTuple!(char, int)) That works. Without the ellipsis. However, that is of course not what yo= u = wanted. I do agree it should, though. --Simen
Mar 30 2008