No aa.byKey.length?
John Colvin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Apr 3 16:46:10 PDT 2016
On Saturday, 2 April 2016 at 16:00:51 UTC, Jonathan M Davis wrote:
> 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
Maybe
aa.byKey().takeExactly(aa.length)
More information about the Digitalmars-d-learn
mailing list