Thread overview
retrieving key and value type of an associative array (D1)
Feb 23, 2011
Funog
Feb 23, 2011
bearophile
Feb 24, 2011
Funog
Feb 24, 2011
bearophile
Feb 24, 2011
Funog
February 23, 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)
February 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
February 24, 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.
February 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
February 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!