Runtime heterogeneous collections?

Neia Neutuladh neia at ikeran.org
Thu Jan 17 02:27:20 UTC 2019


On Thu, 17 Jan 2019 02:21:21 +0000, Steven O wrote:
> I want to create a heterogeneous collection of red-black trees, and I
> can't seem to figure out if it's possible.

RedBlackTree!int and RedBlackTree!string are entirely different types 
(they just happen to be generated from the same template).

There are two reasonable ways of doing things:

1. Make a wrapper class. Now you can store Object[], or you can make a 
base class or base interface and use that.
2. Use Variant, which can wrap anything, or the related Algebraic, which 
can wrap a fixed collection of types.

You can use this technique either with the collection types themselves or 
with the value types.


More information about the Digitalmars-d-learn mailing list