[phobos] Slicer

Jonathan M Davis jmdavisprog at gmail.com
Fri Aug 13 14:29:43 PDT 2010


On Friday, August 13, 2010 14:19:34 David Simcha wrote:
> But this would lead to boilerplate and inefficiency in cases where slicing
> isn't needed.  Ranges that don't have a better way of dealing with slicing
> would have to have lowerLim and upperLim variables and add lowerLim every
> time the range was indexed.  While I think the overhead of this is
> reasonable if the alternative is an algorithm simply not working, I don't
> think it's reasonable to pay for it (both in execution efficiency and
> boilerplate code) when it's not going to be used.

Maybe, random access ranges are just too tied up with arrays in my head, but I 
don't see why it would make sense for a random access range _not_ to have 
slicing like arrays do. In fact, now that I think about it, it surprises me that 
that's not a requirement of random access ranges.

Now, it wouldn't be all that hard to have a string mixin or a template or 
somesuch which produced boiler-plate slicing code in order to reduce code 
duplication, but I really don't understand why random access ranges wouldn't 
have slicing. Ideally, _any_ range would, it just wouldn't be efficient to take 
anything but the whole slice for anything that isn't random access.

- Jonathan M Davis


More information about the phobos mailing list