March 31, 2007 template matching for associative arrays | ||||
---|---|---|---|---|
| ||||
Hi, for arrays there is this way to match arrays in template arguments: class SomeClass(T : T[]) { } But how can you achieve this for AA? class SomeClass(K[V]) { } .. doesn't work. But this does: class SomeClass(K, V, M : K[V]) { } .. but this way you have to know the key and value type in advance which doesn't help to make the code "better". Is there a library function to accomplish this or at least a map type decomposition to key/value types? Thanks in advance. |
April 02, 2007 Re: template matching for associative arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to PNoel | PNoel wrote:
> [...]
> .. doesn't work. But this does:
> class SomeClass(K, V, M : K[V])
> {
> }
> .. but this way you have to know the key and value type in advance
> which doesn't help to make the code "better".
>
> Is there a library function to accomplish this or at least a map type decomposition to key/value types?
I'm no expert on D template syntax, but perhaps you could try this:
class SomeClass(M: K[V], K, V)
{
....
}
Dave
|
Copyright © 1999-2021 by the D Language Foundation