Is it possible to store different generic types in ex. an
Is it possible to store different generic types? via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Nov 9 07:46:26 PST 2016
On Wednesday, 9 November 2016 at 15:44:59 UTC, Is it possible to
store different generic types? wrote:
> Is it possible to store different generic types in ex. somekind
> of container such as an array, hashtable etc.
>
> Let's say we got
>
> class Foo(T) {
> ...
> }
>
> Would it be possible to store something like
>
> Foo[] foos; // Where Foo of course should allow any generic
> version of Foo
>
> Ex.
>
> Foo!int and Foo!string should both be able to be stored inside
> the array.
>
> If so how would one construct an array like that or is there
> some other container that may be able to do it?
I'm aware that I could have Foo inherit a base class and then use
casting, but I would like to avoid casting if possible.
More information about the Digitalmars-d-learn
mailing list