Range length property

Adam D. Ruppe destructionator at gmail.com
Tue Apr 10 14:34:40 UTC 2018


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.


More information about the Digitalmars-d-learn mailing list