Bug 2872 – Length, opIndex for Map

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-04-21T20:01:00Z
Last change time
2015-06-09T01:26:25Z
Keywords
patch
Assigned to
andrei
Creator
dsimcha

Attachments

IDFilenameSummaryContent-TypeSize
482map.dRevised maptext/plain4841

Comments

Comment #0 by dsimcha — 2009-04-21T20:01:46Z
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. ***
Comment #5 by dsimcha — 2010-06-17T19:33:07Z
Fixed in SVN.