digitalmars.D.announce - Re: serialization library - associative arrays ?
- Daniel919 (2/10) Dec 21 2006 Hi, what about associative arrays ?
- Christian Kamm (6/7) Dec 21 2006 They're not supported at the moment as I forgot about them.
- BCS (3/14) Dec 21 2006 static if(is(A in B))
- Lars Ivar Igesund (6/23) Dec 21 2006 opIn is overloadable.
- Christian Kamm (13/16) Dec 21 2006 What I'm planning on using is:
- Thomas Kuehne (12/26) Dec 21 2006 -----BEGIN PGP SIGNED MESSAGE-----
- Christian Kamm (11/14) Dec 21 2006 Good idea! However, it doesn't compile for T =3D int, for example (unles...
- Thomas Kuehne (15/22) Dec 21 2006 -----BEGIN PGP SIGNED MESSAGE-----
- Christian Kamm (8/9) Dec 22 2006 Added support for associative arrays:
What it does not do/is missing: - exception safety / multithread safety - out-of-class/struct serialization methods (is it possible to check whether a specific overload exists at compile time?) - static arrays need to be serialized with describe_staticarray (static arrays can't be inout, so the general-purpose template method doesn't work... is there a way around the problem?) - things I forgot right nowHi, what about associative arrays ? serialization\basicarchive.d(100): static assert (0) is false, "describe called with unsupported type"
Dec 21 2006
Hi, what about associative arrays ?They're not supported at the moment as I forgot about them. 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? Cheers, Christian
Dec 21 2006
Christian Kamm wrote:static if(is(A in B)) ??? IIRC in only works with AAsHi, what about associative arrays ?They're not supported at the moment as I forgot about them. 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? Cheers, Christian
Dec 21 2006
BCS wrote:Christian Kamm wrote:opIn is overloadable. -- Lars Ivar Igesund blog at http://larsivi.net DSource & #D: larsivistatic if(is(A in B)) ??? IIRC in only works with AAsHi, what about associative arrays ?They're not supported at the moment as I forgot about them. 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? Cheers, Christian
Dec 21 2006
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 =3D=3D struct) && !is(T =3D=3D class) && is(typeof(T.keys) KEY =3D=3D KEY[]) && is(typeof(T.values) VALUE =3D=3D VALUE[]) ) { // static assert( is(T =3D=3D VALUE[KEY]) ); } It seems to work, but is rather clumsy. Christian
Dec 21 2006
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Christian Kamm schrieb am 2006-12-21: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-----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.
Dec 21 2006
static if(is(T =3D=3D typeof(T.values[$])[typeof(T.keys[$])]){ // it is an AA, now do your KEY and VALUE magic }Good idea! However, it doesn't compile for T =3D int, for example (unles= s = that was changed between 0.173 and 0.177): - no property 'keys' for type 'int' Why is T.values[$] allowed, though - and is the [$] neccessary? I've so = = far relied on typeof returning the type of the return value for function= s, = but couldn't find it in the spec. Maybe it would be best to use = is(T.values VALUE =3D=3D return)? Christian
Dec 21 2006
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Christian Kamm schrieb am 2006-12-21:Wrong order..., this should work: static if(is(typeof(T.values[0])[typeof(T.keys[0])] == T)){ // it is an AA, now do your KEY and VALUE magic }static if(is(T == typeof(T.values[$])[typeof(T.keys[$])]){ // it is an AA, now do your KEY and VALUE magic }Good idea! However, it doesn't compile for T = int, for example (unless that was changed between 0.173 and 0.177): - no property 'keys' for type 'int'Why is T.values[$] allowed, though - and is the [$] neccessary?$ is used to get an element of the array. You can use any index for that purpose. Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFFi5eGLK5blCcjpWoRAuezAJ9yI+lvn4loaEZX6LuSIZaynCmsQwCdEwOb eC87B4x3YHpqC9TgYuzInDw= =lhKg -----END PGP SIGNATURE-----
Dec 21 2006
Hi, what about associative arrays ?Added support for associative arrays: http://www.math.tu-berlin.de/~kamm/d/serialization.zip I only did a very small unittest for testing the new functionality, so please report further problems and bugs to kamm 'replace with at' math.tu-berlin.de instead of the newsgroup. I've also asked Brad for a project on dsource; once it's set up, further updates will go into the repository there. Christian
Dec 22 2006