opDollar and length

2014-12-28 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
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?

Re: opDollar and length

2014-12-28 Thread Tobias Pankrath via Digitalmars-d-learn
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

Re: opDollar and length

2014-12-28 Thread Jonathan M Davis via Digitalmars-d-learn
/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

Re: opDollar and length

2014-12-28 Thread ketmar via Digitalmars-d-learn
On Sun, 28 Dec 2014 19:02:59 +0100 Joseph Rushton Wakeling via Digitalmars-d-learn digitalmars-d-learn@puremagic.com 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

Re: opDollar and length

2014-12-28 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On 28/12/14 19:21, Tobias Pankrath via Digitalmars-d-learn wrote: 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. Ah, clear. Thanks