D - Templates and recursion
- tunah.d tunah.net (20/20) Feb 04 2004 I was playing around with some collections ideas, and ended up with esse...
- Ivan Senji (9/29) Feb 04 2004 try:
- tunah.d tunah.net (7/43) Feb 04 2004 *slaps forehead* of course!
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
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 withessentiallythe 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, butthiswould be too clumsy to use without type deduction.) Thanks, Sam McCall
Feb 04 2004
*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 withessentiallythe 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, butthiswould be too clumsy to use without type deduction.) Thanks, Sam McCall
Feb 04 2004