templated static array

2012-10-15 Thread Namespace
How can I do this? I have this code: http://dpaste.dzfl.pl/d9165502 And as you can see, the templated function 'receive2' take automatically dynamic arrays. But how can I tell the compiler, that this function takes (preferably) static arrays? My little hack function 'receive' take the type

Re: templated static array

2012-10-15 Thread Simen Kjaeraas
On 2012-05-15 16:10, Namespace rswhi...@googlemail.com wrote: How can I do this? I have this code: http://dpaste.dzfl.pl/d9165502 And as you can see, the templated function 'receive2' take automatically dynamic arrays. But how can I tell the compiler, that this function takes (preferably)

Re: templated static array

2012-10-15 Thread Namespace
So there is no way that the compiler knows by himself how many elements are in the array? something like this: void receive(T, size_t n = vals.length)(T[n] vals) { writeln(typeof(vals).stringof); } or: void receive(T)(T[vals.length] vals) { writeln(typeof(vals).stringof); }

Re: templated static array

2012-10-15 Thread Namespace
On Monday, 15 October 2012 at 15:10:43 UTC, bearophile wrote: Namespace: So there is no way that the compiler knows by himself how many elements are in the array? The syntax I have suggested doesn't have the problem you fear. Why don't you compile and run a little test program? Bye,

Re: templated static array

2012-10-15 Thread bearophile
Namespace: So there is no way that the compiler knows by himself how many elements are in the array? The syntax I have suggested doesn't have the problem you fear. Why don't you compile and run a little test program? Bye, bearophile

Re: templated static array

2012-10-15 Thread Simen Kjaeraas
On 2012-23-15 16:10, Simen Kjaeraas simen.kja...@gmail.com wrote: On 2012-05-15 16:10, Namespace rswhi...@googlemail.com wrote: How can I do this? I have this code: http://dpaste.dzfl.pl/d9165502 And as you can see, the templated function 'receive2' take automatically dynamic arrays. But

Re: templated static array

2012-10-15 Thread Namespace
But bar([1, 2, 3]); not. The compiler does not realize that [1, 2, 3] means a static array in this context. You have to write bar(cast(int[3]) [1, 2, 3]); but I think the compiler have to recognize this on it's own.

Re: templated static array

2012-10-15 Thread Simen Kjaeraas
On 2012-35-15 17:10, Namespace rswhi...@googlemail.com wrote: But bar([1, 2, 3]); not. The compiler does not realize that [1, 2, 3] means a static array in this context. You have to write bar(cast(int[3]) [1, 2, 3]); but I think the compiler have to recognize this on it's own. This is

Re: templated static array

2012-10-15 Thread H. S. Teoh
On Mon, Oct 15, 2012 at 07:05:13PM +0200, Simen Kjaeraas wrote: On 2012-35-15 17:10, Namespace rswhi...@googlemail.com wrote: But bar([1, 2, 3]); not. The compiler does not realize that [1, 2, 3] means a static array in this context. You have to write bar(cast(int[3]) [1, 2, 3]); but I

Re: templated static array

2012-10-15 Thread Kenji Hara
On Monday, 15 October 2012 at 17:05:30 UTC, Simen Kjaeraas wrote: On 2012-35-15 17:10, Namespace rswhi...@googlemail.com wrote: But bar([1, 2, 3]); not. The compiler does not realize that [1, 2, 3] means a static array in this context. You have to write bar(cast(int[3]) [1, 2, 3]); but I think