Concatenate 2 ranges

RazvanN via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Nov 11 05:30:17 PST 2016


I am trying to concatenate 2 ranges of the same type (SortedRange 
in my case). I have tried merge, join and chain, but the problem 
is that the result is not an object of the type of the initial 
ranges. For example:

1. If I use chain(r1, r2), the result will be an object of type 
Result which I cannot cast to my specific type (SortedRange).

2. If I use merge(r1, r2), the result will be an object of type 
Merge!(typeof(r1), typeof(r)).

I know that I can use the .array property, but I think that this 
iterates through all of my elements. Using assumeSorted(chain(r1, 
r2).array) will return a SortedRange, but I am not sure what the 
complexity for this operation is.

Is there a way to concatenate 2 ranges (SortedRange in my case) 
in O(1) time?


More information about the Digitalmars-d-learn mailing list