January 18, 2019 Re: Runtime heterogeneous collections? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Friday, 18 January 2019 at 15:07:41 UTC, Steven Schveighoffer wrote:
> On 1/18/19 9:58 AM, Alex wrote:
>> On Friday, 18 January 2019 at 13:31:28 UTC, Steven Schveighoffer wrote:
>>>[...]
>>
>> 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
Aha... I see... all important methods are templated on the element type... hmm.
|
January 18, 2019 Re: Runtime heterogeneous collections? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven O | On Thursday, 17 January 2019 at 02:21:21 UTC, Steven O wrote:
> void main()
> {
> alias Rec_type = Tuple!(int, "x", int, "y", int, "z");
> RedBlackTree!Rec_type[1] test;
> }
alias Rec_type1 = Tuple!(int, "x", int, "y", int, "z");
alias Rec_type2 = Tuple!(int, "x", int, "y", string, "z");
Tuple!(RedBlackTree!Rec_type1, "x", RedBlackTree!Rec_type2, "z") test;
Similar questions were asked before, usually such heterogeneous collections are not the best solution to the problem at hand.
|
January 20, 2019 Re: Runtime heterogeneous collections? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Seb | I'd like to thank everyone for their help! I was finally able to do what I'd like. I didn't end up using a variant, but maybe there's a better way to do what I want using it, and I just couldn't figure it out. Here's the solution I finally came up with: https://run.dlang.io/is/GdDDBp If anyone has any better solutions I'm all ears! |
Copyright © 1999-2021 by the D Language Foundation