Re: Proper way to accept either static or dynamic array as a parameter

2021-09-11 Thread Alex Bryan via Digitalmars-d-learn
On Sunday, 12 September 2021 at 02:49:48 UTC, jfondren wrote: On Sunday, 12 September 2021 at 02:44:36 UTC, Alex Bryan wrote: `T[] dynArr` can be passed (by reference) to a function that takes `ref T[] data` but `T[10] data` cannot? Why not? ```d void add1(ref int[] nums) { nums ~= 1; } u

Re: Proper way to accept either static or dynamic array as a parameter

2021-09-11 Thread jfondren via Digitalmars-d-learn
On Sunday, 12 September 2021 at 02:44:36 UTC, Alex Bryan wrote: `T[] dynArr` can be passed (by reference) to a function that takes `ref T[] data` but `T[10] data` cannot? Why not? ```d void add1(ref int[] nums) { nums ~= 1; } unittest { int[] nums; nums.add1; nums.add1; num

Re: Proper way to accept either static or dynamic array as a parameter

2021-09-11 Thread Alex Bryan via Digitalmars-d-learn
On Sunday, 12 September 2021 at 01:48:07 UTC, H. S. Teoh wrote: On Sun, Sep 12, 2021 at 01:08:17AM +, Alex Bryan via Digitalmars-d-learn wrote: I am having trouble discovering what the proper (or at least a proper) way is to write a function that can take either a static or dynamic array as

Re: Proper way to accept either static or dynamic array as a parameter

2021-09-11 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Sep 12, 2021 at 01:08:17AM +, Alex Bryan via Digitalmars-d-learn wrote: > I am having trouble discovering what the proper (or at least a proper) > way is to write a function that can take either a static or dynamic > array as a parameter. My current implementation consists of 2 > overl

Proper way to accept either static or dynamic array as a parameter

2021-09-11 Thread Alex Bryan via Digitalmars-d-learn
I am having trouble discovering what the proper (or at least a proper) way is to write a function that can take either a static or dynamic array as a parameter. My current implementation consists of 2 overloaded functions (one takes a dynamic array, the other takes a static array) with 99% copy