How do I initialize a templated constructor?

rempas rempas at tutanota.com
Mon Aug 8 05:38:31 UTC 2022


In the following struct (as an example, not real code):

```
struct TestArray(ulong element_n) {
   int[element_n] elements;

   this(string type)(ulong number) {
     pragma(msg, "The type is: " ~ typeof(type).stringof);
   }
}
```

I want to create it and be able to successfully initialize the 
template parameters
of the constructor but until now, I wasn't able to find a way to 
successfully do
that. Is there a way you guys know?  I have tried the following:

```
void main() {
   // Doesn't work
   auto val = TestArray!(10, "int")(60);

   // Doesn't work either
   auto val = TestArray!(10).TestArray!("int")(60);

   // Neither this works....
   auto val = TestArray!(10).this!("int")(60);
}
```

As with every question I make, the solution must be "betterC" 
compatible so I can use it.
Thanks a lot!


More information about the Digitalmars-d-learn mailing list