[phobos] phobos commit, revision 1566
Andrei Alexandrescu
andrei at erdani.com
Sat May 29 14:17:13 PDT 2010
On 05/29/2010 02:51 PM, Philippe Sigaud wrote:
> Steve:
> > Arguably, Take should never support back and popBack.
> > If you have a random access range, why wouldn't you just do r[0..3]?
>
> Because your range may not have opSlice defined. And is such a slice
> always lazy?
I think the correct answer is that with take(r, 5) you take maximum 5
elements from any range (more general), whereas with r[0 .. 5] you take
exactly 5 elements from a range defining opSlice (most often, random
access) - which is a more specialized function.
There's a tacit rule that has r.opSlice(a, b) return the same type as r
itself.
I'm not sure if take does that already, but it should simply morph into
opSlice() if opSlice() is available. No need to use another layer when
opSlice does what you need.
Andrei
More information about the phobos
mailing list