Re: Auto recursive function

2017-01-12 Thread thedeemon via Digitalmars-d-learn
On Wednesday, 11 January 2017 at 19:23:10 UTC, Razvan Nitu wrote: Hi, I am currently trying to create a function makeMultidimensionalArray which allocates memory for a multidimensional array. You were very close to the answer: auto makeMultidimensionalArray(int N, T, Allocator)(auto ref Al

Re: Auto recursive function

2017-01-12 Thread Bauss via Digitalmars-d-learn
On Thursday, 12 January 2017 at 00:30:33 UTC, Ignacious wrote: On Wednesday, 11 January 2017 at 19:23:10 UTC, Razvan Nitu wrote: [...] If you change the return type to a void* your code basically works. void* makeMultidimensionalArray(T, Allocator)(auto ref Allocator alloc, size_t[] leng

Re: Auto recursive function

2017-01-11 Thread Ignacious via Digitalmars-d-learn
On Wednesday, 11 January 2017 at 19:23:10 UTC, Razvan Nitu wrote: Hi, I am currently trying to create a function makeMultidimensionalArray which allocates memory for a multidimensional array. It is very similar with [1], the difference being that it is uninitialized. Here is the code: auto m

Re: Auto recursive function

2017-01-11 Thread Ignacious via Digitalmars-d-learn
On Wednesday, 11 January 2017 at 19:23:10 UTC, Razvan Nitu wrote: Hi, I am currently trying to create a function makeMultidimensionalArray which allocates memory for a multidimensional array. It is very similar with [1], the difference being that it is uninitialized. Here is the code: auto m

Re: Auto recursive function

2017-01-11 Thread Martin Nowak via Digitalmars-d-learn
On Wednesday, 11 January 2017 at 19:39:17 UTC, Ali Çehreli wrote: return choose(lengths.length == 1, one!T(alloc, lengths[0]), two!T(alloc, lengths)); Well, choose is the right tool when the choice can only be made at runtime. That would be uncommon for dimensionality. Anyhow mentioning

Re: Auto recursive function

2017-01-11 Thread Razvan Nitu via Digitalmars-d-learn
On Wednesday, 11 January 2017 at 19:30:05 UTC, Stefan Koch wrote: On Wednesday, 11 January 2017 at 19:23:10 UTC, Razvan Nitu wrote: Hi, I am currently trying to create a function makeMultidimensionalArray which allocates memory for a multidimensional array. It is very similar with [1], the di

Re: Auto recursive function

2017-01-11 Thread Ali Çehreli via Digitalmars-d-learn
On 01/11/2017 11:30 AM, Stefan Koch wrote: On Wednesday, 11 January 2017 at 19:23:10 UTC, Razvan Nitu wrote: Hi, I am currently trying to create a function makeMultidimensionalArray which allocates memory for a multidimensional array. It is very similar with [1], the difference being that it is

Re: Auto recursive function

2017-01-11 Thread Martin Nowak via Digitalmars-d-learn
On Wednesday, 11 January 2017 at 19:23:10 UTC, Razvan Nitu wrote: auto makeMultidimensionalArray(T, Allocator)(auto ref Allocator alloc, size_t[] lengths) { if (lengths.length == 1) Looks like `static if` would fix your specific problem.

Re: Auto recursive function

2017-01-11 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 11 January 2017 at 19:23:10 UTC, Razvan Nitu wrote: Hi, I am currently trying to create a function makeMultidimensionalArray which allocates memory for a multidimensional array. It is very similar with [1], the difference being that it is uninitialized. Here is the code: [...]

Auto recursive function

2017-01-11 Thread Razvan Nitu via Digitalmars-d-learn
Hi, I am currently trying to create a function makeMultidimensionalArray which allocates memory for a multidimensional array. It is very similar with [1], the difference being that it is uninitialized. Here is the code: auto makeMultidimensionalArray(T, Allocator)(auto ref Allocator alloc, s