Re: `clear`ing a dynamic array

2015-10-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 25, 2015 17:15:50 Shriramana Sharma via Digitalmars-d-learn wrote: > Jonathan M Davis via Digitalmars-d-learn wrote: > > > Appender really isn't intended to be used as a > > container - just as a way to make appending more efficient or to have an > > output range which is an arr

Re: `clear`ing a dynamic array

2015-10-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 25, 2015 16:23:14 Shriramana Sharma via Digitalmars-d-learn wrote: > Thanks all, for your replies. > > Jonathan M Davis via Digitalmars-d-learn wrote: > > > If you want a container rather than a dynamic array - especially if you're > > looking for full reference semantics - then

Re: `clear`ing a dynamic array

2015-10-25 Thread Shriramana Sharma via Digitalmars-d-learn
anonymous wrote: >> I presume this means >> http://dlang.org/phobos/std_array.html#.Appender.reserve but >> how `append` is considered an operator is beyond me. > > That sentence doesn't refer to std.array.Appender. `reserve` > means . The append > op

Re: `clear`ing a dynamic array

2015-10-25 Thread anonymous via Digitalmars-d-learn
On Sunday, 25 October 2015 at 11:45:53 UTC, Shriramana Sharma wrote: http://dlang.org/arrays.html#resize says: """Also, you may wish to utilize the phobos reserve function to pre-allocate array data to use with the append operator.""" I presume this means http://dlang.org/phobos/std_array.htm

Re: `clear`ing a dynamic array

2015-10-25 Thread Shriramana Sharma via Digitalmars-d-learn
Jonathan M Davis via Digitalmars-d-learn wrote: > Appender really isn't intended to be used as a > container - just as a way to make appending more efficient or to have an > output range which is an array I get the part about Appender helping to make an output range of a regular array, but I'm n

Re: `clear`ing a dynamic array

2015-10-25 Thread Shriramana Sharma via Digitalmars-d-learn
Thanks all, for your replies. Jonathan M Davis via Digitalmars-d-learn wrote: > If you want a container rather than a dynamic array - especially if you're > looking for full reference semantics - then use std.container.array.Array. Hmmm, pardon me but while I'm sure I don't specifically require

Re: `clear`ing a dynamic array

2015-10-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 25, 2015 09:34:25 Shriramana Sharma via Digitalmars-d-learn wrote: > rsw0x wrote: > > > use std.container.array > > Thanks all for all the recommendations. When would one use > std.array.appender with a built-in array vs std.container.array.Array? What > are the pros and cons on

Re: `clear`ing a dynamic array

2015-10-25 Thread Olivier Pisano via Digitalmars-d-learn
On Sunday, 25 October 2015 at 04:04:29 UTC, Shriramana Sharma wrote: rsw0x wrote: use std.container.array Thanks all for all the recommendations. When would one use std.array.appender with a built-in array vs std.container.array.Array? What are the pros and cons on either side? Appender

Re: `clear`ing a dynamic array

2015-10-24 Thread qsdfghjk via Digitalmars-d-learn
On Saturday, 24 October 2015 at 13:18:26 UTC, Shriramana Sharma wrote: Hello. I had first expected that dynamic arrays (slices) would provide a `.clear()` method but they don't seem to. Obviously I can always effectively clear an array by assigning an empty array to it, but this has unwanted co

Re: `clear`ing a dynamic array

2015-10-24 Thread Shriramana Sharma via Digitalmars-d-learn
rsw0x wrote: > use std.container.array Thanks all for all the recommendations. When would one use std.array.appender with a built-in array vs std.container.array.Array? What are the pros and cons on either side? -- Shriramana Sharma, Penguin #395953

Re: `clear`ing a dynamic array

2015-10-24 Thread rsw0x via Digitalmars-d-learn
On Saturday, 24 October 2015 at 13:18:26 UTC, Shriramana Sharma wrote: Hello. I had first expected that dynamic arrays (slices) would provide a `.clear()` method but they don't seem to. Obviously I can always effectively clear an array by assigning an empty array to it, but this has unwanted co

Re: `clear`ing a dynamic array

2015-10-24 Thread John Colvin via Digitalmars-d-learn
On Saturday, 24 October 2015 at 13:18:26 UTC, Shriramana Sharma wrote: Hello. I had first expected that dynamic arrays (slices) would provide a `.clear()` method but they don't seem to. Obviously I can always effectively clear an array by assigning an empty array to it, but this has unwanted co

Re: `clear`ing a dynamic array

2015-10-24 Thread anonymous via Digitalmars-d-learn
On 24.10.2015 15:18, Shriramana Sharma wrote: int a[] = [1,2,3,4,5]; Aside: `int[] a;` is the preferred style for array declarations. How to make it so that after clearing `a`, `b` will also point to the same empty array? IOW the desired output is: [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] [] [] .

Re: `clear`ing a dynamic array

2015-10-24 Thread Cauterite via Digitalmars-d-learn
I'm afraid what you're asking for is impossible. Because 'a' and 'b' are both slices, they each have their own 'length' field. When you do 'a = []', you're effectively doing 'a.length = 0'. There's no way to change 'b.length' through 'a'. To get that effect, you'd have to do something like this

`clear`ing a dynamic array

2015-10-24 Thread Shriramana Sharma via Digitalmars-d-learn
Hello. I had first expected that dynamic arrays (slices) would provide a `.clear()` method but they don't seem to. Obviously I can always effectively clear an array by assigning an empty array to it, but this has unwanted consequences that `[]` actually seems to allocate a new dynamic array and