www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Determine if template argument is an array

reply Fractal <happycoding server.com> writes:
Hello

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

Thanks
May 21 2009
next sibling parent reply Fractal <happycoding server.com> writes:
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 21 2009
parent Jarrett Billingsley <jarrett.billingsley gmail.com> writes:
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.
May 22 2009
prev sibling parent Christopher Wright <dhasenan gmail.com> writes:
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 21 2009