Re: Function with static array as parameter

2017-07-12 Thread Miguel L via Digitalmars-d-learn
Thanks for your help.

Re: Function with static array as parameter

2017-07-12 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 12:20:11 UTC, Miguel L wrote: What is the best way in D to create a function that receives a static array of any length? Do know that static arrays are passed by value in D, so passing a static array of a million elements will copy them... There are two solution

Re: Function with static array as parameter

2017-07-12 Thread Rene Zwanenburg via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 12:57:19 UTC, Rene Zwanenburg wrote: On Wednesday, 12 July 2017 at 12:20:11 UTC, Miguel L wrote: What is the best way in D to create a function that receives a static array of any length? Templatize the array length: void foo(size_t length)(int[length] arr) { }

Re: Function with static array as parameter

2017-07-12 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 12:20:11 UTC, Miguel L wrote: What is the best way in D to create a function that receives a static array of any length? You will need to use templates: void foo(size_t N)(int[N] arr) { } -- Biotronic

Re: Function with static array as parameter

2017-07-12 Thread Rene Zwanenburg via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 12:20:11 UTC, Miguel L wrote: What is the best way in D to create a function that receives a static array of any length? Templatize the array length: void foo(size_t length)(int[length] arr) { }

Function with static array as parameter

2017-07-12 Thread Miguel L via Digitalmars-d-learn
What is the best way in D to create a function that receives a static array of any length?

Re: array as parameter

2014-06-07 Thread Paul via Digitalmars-d-learn
On Saturday, 7 June 2014 at 21:32:08 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: On Sat, 07 Jun 2014 20:56:13 + Paul via Digitalmars-d-learn wrote: Dynamic array is really reference. Right? But why modification of parameter in this case does not work: void some_func(string[] s

Re: array as parameter

2014-06-07 Thread Paul via Digitalmars-d-learn
On Saturday, 7 June 2014 at 21:17:41 UTC, monarch_dodra wrote: On Saturday, 7 June 2014 at 20:56:14 UTC, Paul wrote: Dynamic array is really reference. Right? But why modification of parameter in this case does not work: void some_func(string[] s) { s ~= "xxx"; s ~= "yyy"; } but this works:

Re: array as parameter

2014-06-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Sat, 07 Jun 2014 20:56:13 + Paul via Digitalmars-d-learn wrote: > Dynamic array is really reference. Right? But why modification of > parameter in this case does not work: > > void some_func(string[] s) { > s ~= "xxx"; s ~= "yyy"; > } > > but this works: > > void some_fun(ref string[] s)

Re: array as parameter

2014-06-07 Thread monarch_dodra via Digitalmars-d-learn
On Saturday, 7 June 2014 at 20:56:14 UTC, Paul wrote: Dynamic array is really reference. Right? But why modification of parameter in this case does not work: void some_func(string[] s) { s ~= "xxx"; s ~= "yyy"; } but this works: void some_fun(ref string[] s) { s ~= "xxx"; s ~= "yyy"; } In

array as parameter

2014-06-07 Thread Paul via Digitalmars-d-learn
Dynamic array is really reference. Right? But why modification of parameter in this case does not work: void some_func(string[] s) { s ~= "xxx"; s ~= "yyy"; } but this works: void some_fun(ref string[] s) { s ~= "xxx"; s ~= "yyy"; } In the 1st case s is reference too, is not it?