Thread overview
[Beginner] How to add elements to a dynamic array?
Mar 26, 2004
Dave Sieber
Mar 26, 2004
Ivan Senji
Mar 26, 2004
Dave Sieber
March 26, 2004
I want to build an array dynamically, similar to std::vector in C++ :

std::vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);

Can this be done with D arrays?

-- 
dave
March 26, 2004
int[] v;
v ~= 1;
v ~= 2;
v ~= 3;

"Dave Sieber" <dsieber@spamnot.sbcglobal.net> wrote in message news:Xns94B860C93E900dsiebersbc@63.105.9.61...
> I want to build an array dynamically, similar to std::vector in C++ :
>
> std::vector<int> v;
> v.push_back(1);
> v.push_back(2);
> v.push_back(3);
>
> Can this be done with D arrays?
>
> --
> dave


March 26, 2004
"Ivan Senji" <ivan.senji@public.srce.hr> wrote:

> int[] v;
> v ~= 1;
> v ~= 2;
> v ~= 3;

Thank you, Ivan. I had seen this notation in the docs, but the doc said it was for array concatenation. In my case, I wanted to add a single element, not another array, so I assumed it was not the correct way.

IAC, it compiles with your suggested notation. Now, to test it... :-)

-- 
dave