digitalmars.D.learn - retrieving key and value type of an associative array (D1)
- Funog (4/4) Feb 23 2011 static if ( is(abc U : U[]) )
- bearophile (9/11) Feb 23 2011 template AAKeyType(T) {
- Funog (3/14) Feb 24 2011 Thanks ^^ But I actually asked my question wrong ; I also need to check
- bearophile (7/9) Feb 24 2011 Adapted from the module tango.core.Traits:
- Funog (2/11) Feb 24 2011 Thanks!
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
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
Le 23/02/2011 18:36, 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.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 24 2011
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
Le 24/02/2011 13:17, bearophile a écrit :Funog:Thanks!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