Polymorphic recursive class

Jack Applegame via Digitalmars-d digitalmars-d at puremagic.com
Sun Jul 12 23:31:31 PDT 2015


This code doesn't compile, because recursive template expansion.

class Nested(A) {
   A left;
   Nested!(A[]) right;
   this(A l, Nested!(A[]) r) {
     left = l;
     right = r;
   }
}

void main() {
	Nested!int nested = new Nested(1, null);
}

But it successfully compiles in Java an C#. And yes, I know about 
Java type erasure and C# run-time instantiation.

But is there any reason why D can't follow MLton way - 
instantiate a class type template ONLY when a constructor of 
given class is used?



More information about the Digitalmars-d mailing list