Any way to set len and ptr in dyn arrays?
keinfarbton at nospam.xyz
Tue Aug 8 04:50:24 PDT 2006
> Tom S wrote:
>> nobody wrote:
>>> theArray.myArrayInternals.len = buf * buf;
>>> theArray.myArrayInternals.ptr = &buf;
>> erm ...
>> foo = (&buf)[0 .. buf * buf];
> Thanks for your answer. I understand that would ultimately have the same
> result. My question is about whether that directly sets the len and ptr
> fields or are does more stuff happen. If so what is it? If not then why
> is there no direct access to the ptr and len fields?
This builds a slice, which is like setting ptr/length of an array. This
is called slicing. Instead of Toms example, I think you can also write this:
foo = buf[ 2 .. buf * buf + 2 ];
Refering to http://www.digitalmars.com/d/arrays.html
b = a[1..3];
s = t;
s[1..2] = t[0..1];
More information about the Digitalmars-d-learn