Why is std.algorithm so complicated to use?

Jonathan M Davis jmdavisProg at gmx.com
Tue Jul 10 10:30:40 PDT 2012


On Tuesday, July 10, 2012 14:27:14 Simen Kjaeraas wrote:
> On Tue, 10 Jul 2012 09:04:31 +0200, Jonathan M Davis <jmdavisProg at gmx.com>
> 
> wrote:
> > The problem is that map is lazy, so it can't be a random access range,
> 
> Sure it can. If the underlying range is random-access or bidirectional,
> so can map be. What can't be (as easily) done is caching of elements.

Ah, you're right. I'm too used to thinking about filter, but map doesn't change 
the number of elements, so it works just fine as random access (though it risks 
being an efficient way of doing things if the function using it accessing its 
elements multiple times, since it's going to have to call the predicate every 
time that the element is accessed, whereas if you just iterate over the range, 
then odds are that you only access the element once).

- Jonathan M Davis


More information about the Digitalmars-d mailing list