Array of templated classes or structs

qsdfghjk via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Oct 24 09:58:57 PDT 2015


On Saturday, 24 October 2015 at 15:57:09 UTC, Dandyvica wrote:
> Hi guys,
>
> Apart from deriving from the same class and declaring an array 
> of that
> root class, is there a way to create an array of templates?
>
> This seems not possible since template are compile-time 
> generated, but just to be sure. For example, it seems logical 
> to get an array of complex numbers but Complex needs to be 
> declared with a type.
>
> Thanks for any hint.

You can declare an array whose the element type matches to one of 
the template parameter:

---
struct Foo(T)
{
     Foo!T[] foos;
     // typeof(this)[] foos // equivalent
}
---

since it's an array (fixed size whatever is the element type: 
size_t len + size_t pointer) it doesn't matter if the template 
declaration is partial.


More information about the Digitalmars-d-learn mailing list