Thread overview
Determine if template argument is an array
May 21, 2009
Fractal
May 22, 2009
Fractal
May 22, 2009
Christopher Wright
May 21, 2009
Hello

Any body can explan me how to determine if a template argument is an array?

Thanks
May 22, 2009
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
May 22, 2009
Fractal wrote:
> Hello
> 
> Any body can explan me how to determine if a template argument is an array?
> 
> Thanks

Have a look at std.traits or tango.core.Traits. The appropriate way to check is via the templates they define, since it's clearer. Looking at the source will tell you how to replicate the effect should you need to.
May 22, 2009
On Thu, May 21, 2009 at 8:00 PM, Fractal <happycoding@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.