opDollar and length

Tobias Pankrath via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Dec 28 10:21:41 PST 2014


On Sunday, 28 December 2014 at 18:12:42 UTC, Joseph Rushton
Wakeling via Digitalmars-d-learn wrote:
> A question that suddenly occurred to me, and I realized I 
> didn't know the answer.
>
> Why is it necessary/desirable to define separate .length and 
> .opDollar methods for custom types?

To allow slicing for types that don't have a length property but
are terminated by a sentinel value, like null terminated strings
or single linked lists.

It's usefull for multi-dimensional containers as well.


More information about the Digitalmars-d-learn mailing list