How to move append to an array?

Yuxuan Shui via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 15 18:22:49 PDT 2017


On Monday, 15 May 2017 at 23:36:06 UTC, Stanislav Blinov wrote:
> On Monday, 15 May 2017 at 21:38:52 UTC, Yuxuan Shui wrote:
>> Suppose I have a
>>
>> struct A {
>>   @disable this(this);
>> } x;
>>
>> How do I append it into an array?
>>
>> Do I have to do
>>
>> array.length++;
>> moveEmplace(x, array[$-1]);
>>
>> ?
>
> moveEmplace is for moving an initialized object into an 
> uninitialized one. Use the two-argument move() function:
>
> move(x, array[$-1]);

Can I expand an array with uninitialized object? Or can I rely on 
the compiler to optimize the initialization away?


More information about the Digitalmars-d-learn mailing list