Bug 13885 – aa.byKey and aa.byValue don't have a length

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-12-21T16:59:00Z
Last change time
2014-12-25T16:43:38Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-12-21T16:59:06Z
void main() { int[int] aa; size_t len1 = aa.byKey.length; size_t len2 = aa.byValue.length; } Dmd 2.067alpha gives: temp.d(3,27): Error: no property 'length' for type 'Result' temp.d(4,29): Error: no property 'length' for type 'Result'
Comment #1 by safety0ff.bugz — 2014-12-21T18:24:07Z
Implementing this would mean adding a field to byValue / byKey Result range struct which subtracts 1 from the field on each popFront. I'm not convinced there's enough motivation for this feature. // example of an alternative import std.range; auto knownLength(Range) (auto ref Range rng, size_t len) if (isInputRange!Range) { static struct Result { Range r; size_t length; alias r this; auto popFront()() { --length; r.popFront(); } @property bool empty()() { assert(!length == r.empty); return !length; } } return Result(rng, len); } void main() { int[int] aa; auto bykey = aa.byKey.knownLength(aa.length); auto byval = aa.byValue.knownLength(aa.length); }
Comment #2 by bearophile_hugs — 2014-12-25T16:43:38Z
(In reply to safety0ff.bugz from comment #1) > I'm not convinced there's enough motivation for this feature. I agree, I close down this ER.