digitalmars.D.learn - retrieving key and value type of an associative array (D1)
- Funog <funog ifrance.com> Feb 23 2011
- bearophile <bearophileHUGS lycos.com> Feb 23 2011
- Funog <funog ifrance.com> Feb 24 2011
- bearophile <bearophileHUGS lycos.com> Feb 24 2011
- Funog <funog ifrance.com> Feb 24 2011
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: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
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 ^^ 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








Funog <funog ifrance.com>