Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
September 19, 2015 Get AA key and value type | ||||
---|---|---|---|---|
| ||||
Hi everybody, I would like to extract key and value type from AA. I found this answer on forum : template AATypes(T) { // todo: static assert if T is no AA type here alias ArrayElementType!(typeof(T.keys)) key; alias ArrayElementType!(typeof(T.values)) value; } But compiler failed,I think T need to be a value in order to get keys and values attributes. So how can I get types without instance ? Thanks for help. |
September 19, 2015 Re: Get AA key and value type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pierre | On Saturday, 19 September 2015 at 12:50:51 UTC, Pierre wrote: > So how can I get types without instance ? > Thanks for help. ---------->8--------- template AATypes(T) { // todo: static assert if T is no AA type here alias ArrayElementType!(typeof(T.init.keys)) key; alias ArrayElementType!(typeof(T.init.values)) value; } ---------->8--------- Should work. |
September 19, 2015 Re: Get AA key and value type | ||||
---|---|---|---|---|
| ||||
Posted in reply to ponce | On Saturday, 19 September 2015 at 12:52:19 UTC, ponce wrote:
> On Saturday, 19 September 2015 at 12:50:51 UTC, Pierre wrote:
>> So how can I get types without instance ?
>> Thanks for help.
>
> ---------->8---------
>
> template AATypes(T)
> {
> // todo: static assert if T is no AA type here
>
> alias ArrayElementType!(typeof(T.init.keys)) key;
> alias ArrayElementType!(typeof(T.init.values)) value;
> }
>
>
> ---------->8---------
>
>
> Should work.
You're right it's OK now.
Thank you.
|
September 19, 2015 Re: Get AA key and value type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pierre | On Saturday, 19 September 2015 at 12:50:51 UTC, Pierre wrote:
> Hi everybody,
>
> I would like to extract key and value type from AA.
>
You can also do it with built-in syntax:
template AATypes(AA : K[V], K, V)
{
alias Key = K;
alias Value = V;
}
|
September 20, 2015 Re: Get AA key and value type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz | On Saturday, 19 September 2015 at 18:13:09 UTC, Marc Schütz wrote:
> On Saturday, 19 September 2015 at 12:50:51 UTC, Pierre wrote:
>> Hi everybody,
>>
>> I would like to extract key and value type from AA.
>>
>
> You can also do it with built-in syntax:
>
> template AATypes(AA : K[V], K, V)
> {
> alias Key = K;
> alias Value = V;
> }
I see, maybe .KeyType and .ValueType should be integrated in AA.
Or like C++ with map, make a ValueType(::value_type) field wich contain a pair of type.
|
September 20, 2015 Re: Get AA key and value type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz | On Saturday, 19 September 2015 at 18:13:09 UTC, Marc Schütz wrote:
> You can also do it with built-in syntax:
>
> template AATypes(AA : K[V], K, V)
> {
> alias Key = K;
> alias Value = V;
> }
K[V] supposed to be V[K] btw...
|
September 20, 2015 Re: Get AA key and value type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pierre | On 09/20/2015 12:47 AM, Pierre wrote: > I see, maybe .KeyType and .ValueType should be integrated in AA. > Or like C++ with map, make a ValueType(::value_type) field wich contain > a pair of type. Currently, they are templates in std.traits: http://dlang.org/phobos/std_traits.html#KeyType Ali |
September 20, 2015 Re: Get AA key and value type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Sunday, 20 September 2015 at 09:34:15 UTC, Ali Çehreli wrote:
> On 09/20/2015 12:47 AM, Pierre wrote:
>
>> I see, maybe .KeyType and .ValueType should be integrated in AA.
>> Or like C++ with map, make a ValueType(::value_type) field wich contain
>> a pair of type.
>
> Currently, they are templates in std.traits:
>
> http://dlang.org/phobos/std_traits.html#KeyType
>
> Ali
Nice! thank you for the information.
|
Copyright © 1999-2021 by the D Language Foundation