Re: Static array with parameter based size?

2017-07-13 Thread Miguel L via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 18:49:23 UTC, Jack Applegame wrote: On Wednesday, 12 July 2017 at 05:45:13 UTC, Miguel L wrote: Also what is it possible in D to write a function that accepts an static array of any size? void foo(size_t N)(ref int[N] arr) { ... } int[10] arr; foo(arr);

Re: Static array with parameter based size?

2017-07-12 Thread Jack Applegame via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 05:45:13 UTC, Miguel L wrote: Also what is it possible in D to write a function that accepts an static array of any size? void foo(size_t N)(ref int[N] arr) { ... } int[10] arr; foo(arr);

Re: Static array with parameter based size?

2017-07-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 05:45:13 UTC, Miguel L wrote: void f(int x) { int[] my_array; my_array.length=x; but I don't really need a dynamic array as length is not going to change inside f. Then just don't change the length... this is a correct way to do it. You could also allocate it

Re: Static array with parameter based size?

2017-07-11 Thread Miguel L via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 05:45:13 UTC, Miguel L wrote: Hi I need to create a non-dynamic array like this void f(int x) { int[x] my_array; ... this does not compile as x value needs to be known at compile time. The closest to this I can get is: void f(int x) { int[] my_array;

Static array with parameter based size?

2017-07-11 Thread Miguel L via Digitalmars-d-learn
Hi I need to create a non-dynamic array like this void f(int x) { int[x] my_array; ... this does not compile as x value needs to be known at compile time. The closest to this I can get is: void f(int x) { int[] my_array; my_array.length=x; but I don't really need a dynamic array as length

Re: Static array with parameter based size?

2017-07-11 Thread Dgame via Digitalmars-d-learn
On Tuesday, 11 July 2017 at 08:23:02 UTC, Miguel L wrote: I need to create a non-dynamic array like this void f(int x) { int[x] my_array; ... this does not compile as x value needs to be known at compile time. The closest to this I can get is: void f(int x) { int[] my_array;

Re: Static array with parameter based size?

2017-07-11 Thread ketmar via Digitalmars-d-learn
Miguel L wrote: I need to create a non-dynamic array like this void f(int x) { int[x] my_array; ... this does not compile as x value needs to be known at compile time. The closest to this I can get is: void f(int x) { int[] my_array; my_array.length=x; but I don't really need a dynamic

Static array with parameter based size?

2017-07-11 Thread Miguel L via Digitalmars-d-learn
I need to create a non-dynamic array like this void f(int x) { int[x] my_array; ... this does not compile as x value needs to be known at compile time. The closest to this I can get is: void f(int x) { int[] my_array; my_array.length=x; but I don't really need a dynamic array as length is