[Issue 13885] aa.byKey and aa.byValue don't have a length
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Dec 21 10:24:07 PST 2014
https://issues.dlang.org/show_bug.cgi?id=13885
safety0ff.bugz <safety0ff.bugz at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |safety0ff.bugz at gmail.com
--- Comment #1 from safety0ff.bugz <safety0ff.bugz at gmail.com> ---
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);
}
--
More information about the Digitalmars-d-bugs
mailing list