Range length property
Nordlöw
per.nordlow at gmail.com
Tue Apr 10 19:47:10 UTC 2018
On Tuesday, 10 April 2018 at 14:34:40 UTC, Adam D. Ruppe wrote:
> On Tuesday, 10 April 2018 at 14:25:52 UTC, Nordlöw wrote:
>> Should ranges always provide a length property?
>
> No.
>
>> If so, in which cases is a length property an advantage or a
>> requirement?
>
> Just provide it whenever it is cheap to do so. If you need to
> do complex calculations or especially loop over contents to
> figure out the length, do NOT provide it.
>
> But if it is as simple as returning some value, provide it and
> algorithms can take advantage of it for optimizations etc. as
> needed.
I'm thinking of my own container Hashmap having its range
ByKeyValue requiring one extra word of memory to store the
iteration count which, in turn, can be used to calculate the
length of the remaining range. Is this motivated?
More information about the Digitalmars-d-learn
mailing list