templated static array

Simen Kjaeraas simen.kjaras at gmail.com
Mon Oct 15 08:25:04 PDT 2012


On 2012-23-15 16:10, Simen Kjaeraas <simen.kjaras at gmail.com> wrote:

> On 2012-05-15 16:10, Namespace <rswhite4 at 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) static arrays?
>> My little "hack" function 'receive' take the type and the number of  
>> elements. So the compiler know: it's a static array. But is there no  
>> simpler trick to do this?
>> Maybe something like 'void receive(T)(static T vals) {'.
>
> Nope. That's the way to do it.

No, wait, sorry. You don't need to specify those things when calling the
function. This works:

void bar(T, size_t n)(T[n] a) {}

void main(){
     int[3] a;
     bar(a);
}

-- 
Simen


More information about the Digitalmars-d-learn mailing list