nWayUnion(tuple)?

Chris Cain clcain at uncg.edu
Wed Feb 27 15:54:30 PST 2013


On Wednesday, 27 February 2013 at 19:36:44 UTC, bearophile wrote:
> But in some cases I'd like to merge different types of ranges, 
> that I can't put in an array. Is this use case worth supporting 
> (usually the number of ranges is small so for such use cases a 
> heap is not so needed)?

I'm not sure how common the use case is, but I think it'd be 
fairly easy to support.

Just internally have an array of indices to the tuple and use the 
heap with a less defined like "myTup[a] < myTup[b]" to use the 
indices to look into the tuple to sort the indices appropriately. 
Just add some compile-time checks to make sure all of the 
ElementTypes of the tuple agree and it's essentially the same 
thing as already implemented.

It actually probably wouldn't be a terrible idea to write a 
wrapper range that does this type of process so that it may be 
used with anything and the wrapper range could be a 
RandomAccessRange... this would (probably) make it possible to 
use tuples in a lot of places it isn't exactly allowed right now.


More information about the Digitalmars-d-learn mailing list