Runtime heterogeneous collections?

Steven Schveighoffer schveiguy at gmail.com
Fri Jan 18 15:07:41 UTC 2019


On 1/18/19 9:58 AM, Alex wrote:
> 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?

But what is the common interface between those 2 types? Even in 
Dcollections, where RedBlackTree came from, there was no interfaces that 
didn't specify the type they were dealing with. In other words, there is 
no common interface for sets of 2 different types.

-Steve


More information about the Digitalmars-d-learn mailing list