www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - retrieving key and value type of an associative array (D1)

reply Funog <funog ifrance.com> writes:
static if ( is(abc U : U[]) )

... aliases U to whatever abc is an array of.
In the case of an associative array, is it possible to retrieve both the 
value and key type? (D1)
Feb 23 2011
parent reply bearophile <bearophileHUGS lycos.com> writes:
Funog:

 In the case of an associative array, is it possible to retrieve both the 
 value and key type? (D1)

template AAKeyType(T) { alias typeof(T.keys[0]) AAKeyType; } template AAValType(T) { alias typeof(T.values[0]) AAValType; } Bye, bearophile
Feb 23 2011
parent reply Funog <funog ifrance.com> writes:
Le 23/02/2011 18:36, bearophile a écrit :
 Funog:

 In the case of an associative array, is it possible to retrieve both the
 value and key type? (D1)

template AAKeyType(T) { alias typeof(T.keys[0]) AAKeyType; } template AAValType(T) { alias typeof(T.values[0]) AAValType; } Bye, bearophile

Thanks ^^ But I actually asked my question wrong ; I also need to check whether abc is an associative array or not.
Feb 24 2011
parent reply bearophile <bearophileHUGS lycos.com> writes:
Funog:

 Thanks ^^ But I actually asked my question wrong ; I also need to check 
 whether abc is an associative array or not.

Adapted from the module tango.core.Traits: template IsAA(T) { const bool IsAA = is( typeof(T.init.values[0])[typeof(T.init.keys[0])] == T ); } Bye, bearophile
Feb 24 2011
parent Funog <funog ifrance.com> writes:
Le 24/02/2011 13:17, bearophile a écrit :
 Funog:

 Thanks ^^ But I actually asked my question wrong ; I also need to check
 whether abc is an associative array or not.

Adapted from the module tango.core.Traits: template IsAA(T) { const bool IsAA = is( typeof(T.init.values[0])[typeof(T.init.keys[0])] == T ); } Bye, bearophile

Thanks!
Feb 24 2011