www.digitalmars.com         C & C++   DMDScript  

D - Templates and recursion

reply tunah.d tunah.net writes:
I was playing around with some collections ideas, and ended up with essentially
the following:

class TFoo(T) {
this() {}
this(TFoo!(T) tf) {}     // this is the problem line
}

int main() {
alias TFoo!(Object) x;
x a = new x();
return 0;
}

The error I got was "template instance TFoo!(int) TFoo is not a template
declaration"
Am I doing something wrong, or is this just not supported yet?

(What i _really_ wanted was 
this(TFoo!(S : T) tf) {}
to allow more complete but still typesafe copying into a collection, but this
would be too clumsy to use without type deduction.)

Thanks,
Sam McCall
Feb 04 2004
parent reply "Ivan Senji" <ivan.senji public.srce.hr> writes:
try:

class TFoo(T)
{
    this() {}
    this(TFoo tf) {}
}

<tunah.d tunah.net> wrote in message news:bvqr28$11nq$1 digitaldaemon.com...
 I was playing around with some collections ideas, and ended up with
essentially
 the following:

 class TFoo(T) {
 this() {}
 this(TFoo!(T) tf) {}     // this is the problem line
 }

 int main() {
 alias TFoo!(Object) x;
 x a = new x();
 return 0;
 }

 The error I got was "template instance TFoo!(int) TFoo is not a template
 declaration"
 Am I doing something wrong, or is this just not supported yet?

 (What i _really_ wanted was
 this(TFoo!(S : T) tf) {}
 to allow more complete but still typesafe copying into a collection, but
this
 would be too clumsy to use without type deduction.)

 Thanks,
 Sam McCall
Feb 04 2004
parent tunah.d tunah.net writes:
*slaps forehead* of course!
this(.TFoo!(T) tf) {}
also works, and lets you specify the type... I wonder how you would do if if you
needed to specify, say, TFoo!(Object) and the template wasn't at the top level?
Thanks,
Sam McCall

In article <bvqrmo$12s9$1 digitaldaemon.com>, Ivan Senji says...
try:

class TFoo(T)
{
    this() {}
    this(TFoo tf) {}
}

<tunah.d tunah.net> wrote in message news:bvqr28$11nq$1 digitaldaemon.com...
 I was playing around with some collections ideas, and ended up with
essentially
 the following:

 class TFoo(T) {
 this() {}
 this(TFoo!(T) tf) {}     // this is the problem line
 }

 int main() {
 alias TFoo!(Object) x;
 x a = new x();
 return 0;
 }

 The error I got was "template instance TFoo!(int) TFoo is not a template
 declaration"
 Am I doing something wrong, or is this just not supported yet?

 (What i _really_ wanted was
 this(TFoo!(S : T) tf) {}
 to allow more complete but still typesafe copying into a collection, but
this
 would be too clumsy to use without type deduction.)

 Thanks,
 Sam McCall
Feb 04 2004