Kind of a meta-enhancement, but it would be nice if all of the generic range types in std.range and std.algorithm would try to have length properties if the range that they're wrapping does. For example, as far as I can tell, it wouldn't be hard to make Map have a length property that forwards to the underlying range's length property if it exists.
This would primarily be useful when copying generic ranges to an array, as this can be done much more efficiently if the length is known ahead of time and the array can be allocated exactly once, rather than appending.
Comment #1 by dsimcha — 2009-05-13T06:47:11Z
Now that I've played around more with the new Phobos, this is really just an issue with map. Also, opIndex for map seems like a reasonable proposition.
Comment #2 by dsimcha — 2009-10-27T20:58:34Z
Created attachment 482
Revised map
Comment #3 by dsimcha — 2009-10-27T21:00:10Z
Here's a revised map that supports bidirectional ranges, slicing, length and random access if the underlying range supports these.
You may want to note in the docs, however, that random access indexing isn't cached and therefore should only be used frequently if fun is cheap.
Comment #4 by dsimcha — 2010-06-17T19:28:06Z
*** Issue 3871 has been marked as a duplicate of this issue. ***