View mode: basic / threaded / horizontal-split · Log in · Help
March 07, 2013
request: indexed(inputRange, sortedInputRange)
right now std.range.indexed takes a randomAccessRange of elements 
and a inputRange of indexes.

Why not also support lazy inputs, with sorted integral indexes ?
That's make it possible to, say, get every 10 lines of a file, 
lazily.

right now:
struct Indexed(Source, Indices) if (isRandomAccessRange!(Source) 
&& isInputRange!(Indices) && 
is(typeof(Source.init[ElementType!(Indices).init])));
Indexed!(Source, Indices) indexed(Source, Indices)(Source source, 
Indices indices);


here's what's proposed, in addition to above:
struct Indexed(Source, Indices) if (isInputRange!(Source) && 
isSortedInputRange!(Indices) && 
isIntegral!(ElementType!(Indices)));
Indexed!(Source, Indices) indexed(Source, Indices)(Source source, 
Indices indices);

where a SortedInputRange represents a sorted input range (we 
could for eg construct one as assumeSorted()), and it there could 
be CT optimizations based on the type (eg: Iota would be sorted).

Implementation:
simply call popFront indexes[0] times and then popFront 
indexes[i+1]-indexes[i] times for each subsequent index.
Top | Discussion index | About this forum | D home