On Sunday, 12 March 2017 at 01:55:20 UTC, ketmar wrote:
Random D user wrote:

How come string* suddenly has a .length property?

due to automatic pointer dereferencing that `.` does. no, not a bug.

Ah... right. Silly me. Of course, since string is actually immutable(char)[]. That's bit of a nasty corner case where -> == . isn't that nice. Fortunately, it's rare.

Thanks.

This happened to me, when I was packing stuff into SoA layout and didn't want to duplicate the length in the struct (implicitly by using []). Of course, I forgot to update one place to use the shared length.
That is:

length
ptr
ptr
ptr

instead of

ptr
length
ptr
length
ptr
length

Perhaps I should do a SoA layout template that somehow disables .length on individual arrays.

Reply via email to