type of array element, type of assoz key?

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Aug 5 06:36:53 PDT 2007


"dennis luehring" <dl.soluz at gmx.net> wrote in message 
news:f94bnb$18j0$1 at digitalmars.com...
> and how can i differ between assoc arrays and dynamic ones?
>

template isDynArray(T)
{
    const isDynArray = false;
}

template isDynArray(T : T[])
{
    const isDynArray = true;
}

template isAssocArray(T)
{
    const isAssocArray = is(typeof(T.values[0])[typeof(T.keys[0])] == T);
}

A metafunction to determine if a type is a static array exists in std.traits 
in Phobos, and in tango.core.Traits in Tango.

If you're using D 2, you can also find out if something is an AA by using 
__traits(isAssociativeArray, T).  There's __traits(isStaticArray, T) as 
well, but no __traits(isDynamicArray, T).

Although I agree with you that runtime type introspection of complex types 
should be done using .something rather than the mess of hackish looking 
constructs that we have now.  .keytype and .valuetype for AAs; .valuetype 
for arrays, pointers, and typedefs; .returntype and .parametertypes for 
functions, func pointers, and delegates.  Rather than typeof(T.keys[0]), 
typeof(T.values[0]), typeof(T[0]), typeof(*T), is(T Base == typedef), is(T 
Return == return), and is(T params == function). 




More information about the Digitalmars-d-learn mailing list