How do I initialize a templated constructor?

Ali Çehreli acehreli at yahoo.com
Mon Aug 8 14:06:17 UTC 2022


Here is another one that uses nested templates:

import std.stdio;

template TestArray(ulong element_n) {
   struct TestArrayImpl(Type) {
     int[element_n] elements;

     this(ulong number) {
       pragma(msg, "The type is: ", Type);
       writeln("Constructing with ", number);
     }
   }

   auto makeFor(string s)(ulong number) {
     return TestArrayImpl!(mixin(s))(number);
   }
}

void main() {
   auto ta = TestArray!10.makeFor!"int"(60);
}

Ali



More information about the Digitalmars-d-learn mailing list