Best interface for memcpy() (and the string.h family of functions)
kinke
noone at nowhere.com
Thu May 30 01:19:54 UTC 2019
On Thursday, 30 May 2019 at 00:18:06 UTC, Stefanos Baziotis wrote:
> The current state is that we think that slices should be enough
> for this need.
> Meaning, you don't need the third size parameter. In this case,
> ref is better. On the other, in other cases I think that
> pointers
> are more intuitive.
In D, there's no ugly and unsafe need to pass slices to memcpy,
as a simple `dst[] = src[]` can do the job much better, boiling
down to a memcpy (with 3rd param) if T is a POD (and the two
slices don't overlap, have the same length etc. if bounds checks
are enabled).
Taking a slice by ref, if I understand you correctly, would
firstly only work with slice lvalues (i.e., no `ptr[0..$-1]`
rvalues), and secondly IMO be very confusing and bad for generic
code, as I would expect the slice itself to be memcopied then,
not its contents.
More information about the Digitalmars-d
mailing list