fast way to insert element at index 0
Baz via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jun 23 07:20:42 PDT 2015
On Tuesday, 23 June 2015 at 13:29:41 UTC, Steven Schveighoffer
wrote:
> On 6/23/15 8:12 AM, Baz wrote:
>> On Tuesday, 23 June 2015 at 11:22:31 UTC, Steven Schveighoffer
>> wrote:
>>>[...]
>>
>> according to the C library, memmove handle overlapps, you
>> mismatch with
>> memcpy which does not.
>>
>
> The above is not memmove, it's slice assignment, which is
> specifically illegal for overlaps:
>
> $ cat testsliceassign.d
> void buffer[100];
>
> void main()
> {
> buffer[1..$] = buffer[0..$-1];
> }
>
> $ dmd testsliceassign.d
> $ ./testsliceassign
> object.Error@(0): Overlapping arrays in copy: 98 byte(s)
> overlap of 99
>
> -Steve
ok. i was, wrongly, suposing that this operation uses memmove
under the hood.
btw you forgot to grow the array size, if i dare.
More information about the Digitalmars-d-learn
mailing list