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?

Reply via email to