On Thursday, 26 May 2016 at 22:47:02 UTC, Era Scarecrow wrote:
On Thursday, 26 May 2016 at 22:15:42 UTC, ag0aep6g wrote:
Sorry, I'm still lost. Why can't you do whatever you're doing
in opOpAssign directly there, or in a free function? Does the
pseudo-array contain any additional data? Would a wrapper
around a built-in array not work?
Well a few things at work. First the array is originally a
static array, so I pass it as a slice; But if you pass it as a
slice you get the entire length, and modifying the length
requires either changing length or appending, both which may
cause allocation (something I want to avoid). By making my own
compatible structure I can manage the length and pointer
directly and precisely.
You can do that with arrays, too, without causing allocations:
assert(slice.length < static_array.length);
slice = slice.ptr[0 .. slice.length+1];
Of course that's unsafe, but your pointer magic certainly is, too.