No aa.byKey.length?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Apr 2 09:00:51 PDT 2016


On Saturday, April 02, 2016 15:38:30 Ozan via Digitalmars-d-learn wrote:
> On Friday, 1 April 2016 at 20:50:32 UTC, Yuxuan Shui wrote:
> > Why?
> >
> > This is annoying when I need to feed it into a function that
> > requires hasLength.
>
> aa.keys.length

That allocates an array. Doing that would be like doing
aa.byKeys().array().length. And associate arrays already have length. You
can do

auto len = aa.length;

The problem is when you want to operate on a range, and the function that
you want to pass it to wants length on the range. If byKeys returned a range
with length, then that would work, but since it doesn't, it doesn't. Having
other ways to get the length doesn't help.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list