Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
February 23, 2011 retrieving key and value type of an associative array (D1) | ||||
---|---|---|---|---|
| ||||
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) |
February 23, 2011 Re: retrieving key and value type of an associative array (D1) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Funog | 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
|
February 24, 2011 Re: retrieving key and value type of an associative array (D1) | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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.
|
February 24, 2011 Re: retrieving key and value type of an associative array (D1) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Funog | 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 |
February 24, 2011 Re: retrieving key and value type of an associative array (D1) | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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!
|
Copyright © 1999-2021 by the D Language Foundation