serialization library - associative arrays ?
Thomas Kuehne
thomas-dloop at kuehne.cn
Thu Dec 21 13:51:37 PST 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Christian Kamm schrieb am 2006-12-21:
>> Hm, is there a way to check if a template parameter is an associative
>> array and to get the key and value type without relying on .keys and
>> .values?
>
> What I'm planning on using is:
>
> static if(
> !is(T == struct) &&
> !is(T == class) &&
> is(typeof(T.keys) KEY == KEY[]) &&
> is(typeof(T.values) VALUE == VALUE[])
> )
> {
> // static assert( is(T == VALUE[KEY]) );
> }
>
> It seems to work, but is rather clumsy.
static if(is(T == typeof(T.values[$])[typeof(T.keys[$])]){
// it is an AA, now do your KEY and VALUE magic
}
Thomas
-----BEGIN PGP SIGNATURE-----
iD8DBQFFiw7sLK5blCcjpWoRAgo/AJ9tHEUAyHIqMhfQoVpjn5KzflyDGACfVkat
ee+l8Xs6TcF0ehosTuNmbcw=
=k0XH
-----END PGP SIGNATURE-----
More information about the Digitalmars-d-announce
mailing list