template specialization for arrays

Steven Schveighoffer schveiguy at yahoo.com
Mon Oct 31 05:13:16 PDT 2011


On Sat, 29 Oct 2011 12:11:42 -0400, J Arrizza <cppgent0 at gmail.com> wrote:

> Thanks for the reply Jonathan, but it didn't work for me:
>
> void abc(T) (T[] parm1)
> if (isDynamicArray!T)
> {
>   writeln("array : ", parm1);
> }
>
>
> Nor did:
>
> void abc(T) (T[] parm1)
> if (isStaticArray!T)
> {
>   writeln("array : ", parm1);
> }
>
>
> Output is the same:
>
> simpleparm: 1
> simpleparm: str
> simpleparm: [1, 2]

I know you've since figured it out, but I thought I'd point out why this  
didn't work.

The reason it doesn't match is because your parameters are arrays of type  
T, but you are only instantiating if T *itself* is an array.  So for  
example, int[][] would work, because T is matched as int[], giving int[][]  
as the parm1 type.

-Steve


More information about the Digitalmars-d mailing list