Re: How to detect if an array if dynamic or static

2016-02-25 Thread Ali Çehreli via Digitalmars-d-learn
On 02/25/2016 04:47 AM, sigod wrote: > void bar(ref int[] arr) > > Code wouldn't compile if you try to pass static array as `ref` argument. To qualify further, static arrays cannot be passed as slice references because although there is an automatic slicing of static arrays, such slices a

Re: How to detect if an array if dynamic or static

2016-02-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/24/16 9:08 PM, Adam D. Ruppe wrote: On Thursday, 25 February 2016 at 01:31:17 UTC, Chris Wright wrote: When you get to GC-allocated stuff, there's no way to tell. The GC is easy, you can simply ask it: http://dpldocs.info/experimental-docs/core.memory.GC.addrOf.1.html "If p references m

Re: How to detect if an array if dynamic or static

2016-02-25 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 24 February 2016 at 21:48:14 UTC, mahdi wrote: Suppose we have a function like this: void diss(int[] array) ... How can we detect is `array` is static (fixed size) or dynamic, inside the function body? I don't see that anyone has mentioned it but: https://dlang.org/phobos/std_

Re: How to detect if an array if dynamic or static

2016-02-25 Thread Chris Wright via Digitalmars-d-learn
On Thu, 25 Feb 2016 02:08:18 +, Adam D. Ruppe wrote: > On Thursday, 25 February 2016 at 01:31:17 UTC, Chris Wright wrote: >> When you get to GC-allocated stuff, there's no way to tell. > > The GC is easy, you can simply ask it: > > http://dpldocs.info/experimental-docs/core.memory.GC.addrOf.

Re: How to detect if an array if dynamic or static

2016-02-25 Thread asdf via Digitalmars-d-learn
On Wednesday, 24 February 2016 at 21:48:14 UTC, mahdi wrote: Suppose we have a function like this: void diss(int[] array) ... How can we detect is `array` is static (fixed size) or dynamic, inside the function body? I don't understand what I'm doing but got a proof of concept for you. This

Re: How to detect if an array if dynamic or static

2016-02-25 Thread sigod via Digitalmars-d-learn
On Thursday, 25 February 2016 at 12:18:07 UTC, mahdi wrote: On Thursday, 25 February 2016 at 11:50:02 UTC, sigod wrote: On Thursday, 25 February 2016 at 10:03:08 UTC, mahdi wrote: Thanks. So when we define the function, we MUST specify the array size to be able to accept a static array? Can't

Re: How to detect if an array if dynamic or static

2016-02-25 Thread sigod via Digitalmars-d-learn
On Thursday, 25 February 2016 at 12:18:07 UTC, mahdi wrote: On Thursday, 25 February 2016 at 11:50:02 UTC, sigod wrote: On Thursday, 25 February 2016 at 10:03:08 UTC, mahdi wrote: Thanks. So when we define the function, we MUST specify the array size to be able to accept a static array? Can't

Re: How to detect if an array if dynamic or static

2016-02-25 Thread mahdi via Digitalmars-d-learn
On Thursday, 25 February 2016 at 11:50:02 UTC, sigod wrote: On Thursday, 25 February 2016 at 10:03:08 UTC, mahdi wrote: Thanks. So when we define the function, we MUST specify the array size to be able to accept a static array? Can't we just define a function which can accept any static array

Re: How to detect if an array if dynamic or static

2016-02-25 Thread sigod via Digitalmars-d-learn
On Thursday, 25 February 2016 at 10:03:08 UTC, mahdi wrote: Thanks. So when we define the function, we MUST specify the array size to be able to accept a static array? Can't we just define a function which can accept any static array with any size? (e.g. a function to calculate average of a s

Re: How to detect if an array if dynamic or static

2016-02-25 Thread Kagamin via Digitalmars-d-learn
void diss(int n)(ref int[n] array) { } But to consume array of any size, just take dynamic array as parameter.

How to detect if an array if dynamic or static

2016-02-25 Thread mahdi via Digitalmars-d-learn
Thanks. So when we define the function, we MUST specify the array size to be able to accept a static array? Can't we just define a function which can accept any static array with any size? (e.g. a function to calculate average of a static int array of any size)?

Re: How to detect if an array if dynamic or static

2016-02-24 Thread Ali Çehreli via Digitalmars-d-learn
On 02/24/2016 08:44 PM, mahdi wrote: > On Wednesday, 24 February 2016 at 22:38:04 UTC, Adam D. Ruppe wrote: >> On Wednesday, 24 February 2016 at 21:48:14 UTC, mahdi wrote: >>> How can we detect is `array` is static (fixed size) or dynamic, >>> inside the function body? >> >> `array` there is alway

Re: How to detect if an array if dynamic or static

2016-02-24 Thread mahdi via Digitalmars-d-learn
On Wednesday, 24 February 2016 at 22:38:04 UTC, Adam D. Ruppe wrote: On Wednesday, 24 February 2016 at 21:48:14 UTC, mahdi wrote: How can we detect is `array` is static (fixed size) or dynamic, inside the function body? `array` there is always dynamic because it is not of a fixed size type.

Re: How to detect if an array if dynamic or static

2016-02-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 25 February 2016 at 01:31:17 UTC, Chris Wright wrote: When you get to GC-allocated stuff, there's no way to tell. The GC is easy, you can simply ask it: http://dpldocs.info/experimental-docs/core.memory.GC.addrOf.1.html "If p references memory not originally allocated by this gar

Re: How to detect if an array if dynamic or static

2016-02-24 Thread Chris Wright via Digitalmars-d-learn
On Wed, 24 Feb 2016 21:48:14 +, mahdi wrote: > Suppose we have a function like this: > > void diss(int[] array) ... > > How can we detect is `array` is static (fixed size) or dynamic, > inside the function body? Static arrays point to memory on the stack, inside an aggregate type on the he

Re: How to detect if an array if dynamic or static

2016-02-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 24 February 2016 at 21:48:14 UTC, mahdi wrote: How can we detect is `array` is static (fixed size) or dynamic, inside the function body? `array` there is always dynamic because it is not of a fixed size type. Why do you want to know though?

How to detect if an array if dynamic or static

2016-02-24 Thread mahdi via Digitalmars-d-learn
Suppose we have a function like this: void diss(int[] array) ... How can we detect is `array` is static (fixed size) or dynamic, inside the function body?