Runtime heterogeneous collections?

Alex sascha.orlov at gmail.com
Fri Jan 18 14:58:41 UTC 2019


On Friday, 18 January 2019 at 13:31:28 UTC, Steven Schveighoffer 
wrote:
> To answer the OP, what he wants is an array of different 
> RedBlackTrees. Since RedBlackTree is a class, his code is not 
> far off from something that works. This does compile, and 
> produces an Object[]:
>
>     auto arr = [
>  redBlackTree(Tuple!(int, "x", int, "y", string, "z")(1, 2, 
> "abc")),
>  redBlackTree(Tuple!(int, "x", int, "y", int, "z")(1, 2, 3))
> ];
>
> Then you have to cast each object into it's appropriate type to 
> use it. That is not as easy, as you have to know the exact 
> instantiation of tree type.
>

In this case, I would say Phobos lacks an appropriate interface 
definition, what do you think?


More information about the Digitalmars-d-learn mailing list