Determine if template argument is an array

Jarrett Billingsley jarrett.billingsley at gmail.com
Fri May 22 09:24:53 PDT 2009


On Thu, May 21, 2009 at 8:00 PM, Fractal <happycoding at server.com> wrote:
> Fractal Wrote:
>
>> Hello
>>
>> Any body can explan me how to determine if a template argument is an array?
>
> ...And also if is an associative array
>
>> Thanks
>

You can also use template specialization, which, depending on your use
case, might be shorter and clearer than a static if.

template Foo(T: T[]) will specialize for dynamic array arguments.  T
will be the element type (so for int[], T will be int).
template Foo(T: T[n], size_t n) will specialize for static array
arguments. T will be the element type like above, and n will be the
size of the array.
template Foo(T: T[K], K) will specialize for associative array
arguments.  T will be the value type, and K will be the key type.


More information about the Digitalmars-d-learn mailing list