Re: A slice can lose capacity simply by calling a function

2015-05-04 Thread Ali Çehreli via Digitalmars-d-learn
On 05/03/2015 06:06 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Sunday, May 03, 2015 15:21:15 Andrew Godfrey via Digitalmars-d-learn wrote: I really don't think that it's an issue in general, but if you do want to guarantee that nothing affects the capacity of your array, then

Re: A slice can lose capacity simply by calling a function

2015-05-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, 4 May 2015 at 06:23:42 UTC, Ali Çehreli wrote: On 05/03/2015 06:06 PM, Jonathan M Davis via Digitalmars-d-learn wrote: (I am eagerly waiting for your DConf talk to see how you make sense of it all.) Well, we'll see how much I'm able to cover about arrays. The focus of the talk

Re: A slice can lose capacity simply by calling a function

2015-05-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 03, 2015 15:21:15 Andrew Godfrey via Digitalmars-d-learn wrote: I really don't think that it's an issue in general, but if you do want to guarantee that nothing affects the capacity of your array, then you're going to need to either wrap all access to it I agree with

Re: A slice can lose capacity simply by calling a function

2015-05-03 Thread Andrew Godfrey via Digitalmars-d-learn
I really don't think that it's an issue in general, but if you do want to guarantee that nothing affects the capacity of your array, then you're going to need to either wrap all access to it I agree with everything Jonathan said in both threads EXCEPT that this is not an issue. The

Re: A slice can lose capacity simply by calling a function

2015-05-03 Thread Meta via Digitalmars-d-learn
On Sunday, 3 May 2015 at 15:21:17 UTC, Andrew Godfrey wrote: I really don't think that it's an issue in general, but if you do want to guarantee that nothing affects the capacity of your array, then you're going to need to either wrap all access to it I agree with everything Jonathan said

Re: A slice can lose capacity simply by calling a function

2015-05-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, May 02, 2015 01:21:14 Ali Çehreli via Digitalmars-d-learn wrote: 2) void foo(const(int[]) arr); // cannot affect anything // (even capacity) Actually, you can modify the capacity of arr quite easily. All you have to do is slice it

A slice can lose capacity simply by calling a function

2015-05-02 Thread Ali Çehreli via Digitalmars-d-learn
This is related to a discussion[1] that I had started recently but I will give an even shorter example here: void main() { // Two slices to all element auto a = [ 1, 2, 3, 4 ]; auto b = a; // Initially, they both have capacity (strange! :) ) assert(a.capacity == 7);

Re: A slice can lose capacity simply by calling a function

2015-05-02 Thread Ali Çehreli via Digitalmars-d-learn
On 05/02/2015 01:56 AM, Jonathan M Davis via Digitalmars-d-learn wrote: I really don't think that it's reasonable in the general case to expect to be able to guarantee that the capacity of a dynamic array won't change. Yes, it is very different from other languages like C and C++ that

Re: A slice can lose capacity simply by calling a function

2015-05-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, May 02, 2015 07:46:27 Ali Çehreli via Digitalmars-d-learn wrote: On 05/02/2015 01:56 AM, Jonathan M Davis via Digitalmars-d-learn wrote: I really don't think that it's reasonable in the general case to expect to be able to guarantee that the capacity of a dynamic array won't