How to move append to an array?

biocyberman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 18 02:31:13 PDT 2017


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]);
>
> ?

  Judging form the way you write the struct. It is of C/C++ style. 
With that said,
it's not clear what you are trying to do. There is a basic 
reference about array here:
http://dlang.org/spec/arrays.html

And this works:

cat arrayappend.d
// arrayappend.d content
unittest {
   auto a = [1, 2];
   a ~= 3;
   assert( a == [1, 2, 3]);
}
// Finish content

Running test:

rdmd -unittest -main arrayappend.d

No error message means the test passes.



More information about the Digitalmars-d-learn mailing list