Array Slice Ranges

Daniel Keep daniel.keep.lists at gmail.com
Thu Nov 9 18:09:15 PST 2006



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...)

	-- Daniel

-- 
Unlike Knuth, I have neither proven or tried the above; it may not even
make sense.

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/



More information about the Digitalmars-d mailing list