Array Slice Ranges

Georg Wrede georg.wrede at nospam.org
Sun Nov 12 14:32:33 PST 2006


Daniel Keep wrote:
> 
> Pragma wrote:
> 
>>...
>>
>>The only way to satisfy all of the above cleanly, is as a library type
>>that masquerades as an array.  Something like a templated struct could
>>do the job nicely, and would cover more range types than just integer
>>sequences.  In essence, I think the need for a range type w/array
>>semantics, is one-and-the-same with the need for an iterator
>>implementation.  They're just two different flavors of the same thing:
>>one iterates an actual data set (which built-in arrays do implicitly),
>>the other pulls values out of thin air.
> 
> 
> Which brings up an interesting idea...
> 
> 
>>auto range = new Range!(int)(0,10,2); // 0-10 with 2 step
>>auto evens = someArray[range]; // extract even elements
> 
> 
> Would be really cool since you could fiddle with the range to get
> exactly the set of elements you want, and then extract them all in one
> pass.  But if you're going to do that, why not just allow the "range"
> bit be any old iterator that iterates over keys?
> 
> 
>>auto range = AllPeople.marriedIterator;
>>auto shackled = AllPeople[range];
> 
> 
> Just a thought :3 Maybe we should just MAKE a library implementation of
> a range, hand it to Walter and say "let's make this standard".
> 
> We can then write mixins to be used by library code for using ranges
> inside of opIndex; it should be possible to express opIndex(range) in
> terms of opIndex(key).  Maybe if we can a standard iterator
> interface/base class/whatever, we can do the same to allow for slicing
> using an interator.
> 
> (Also thinking out loud...)

My gut is listening, and it's starting to feel pretty good!



More information about the Digitalmars-d mailing list