Thread overview
Re: serialization library - associative arrays ?
Dec 21, 2006
Daniel919
Dec 21, 2006
Christian Kamm
Dec 21, 2006
BCS
Dec 21, 2006
Lars Ivar Igesund
Dec 21, 2006
Christian Kamm
Dec 21, 2006
Thomas Kuehne
Dec 21, 2006
Christian Kamm
Dec 22, 2006
Thomas Kuehne
Dec 22, 2006
Christian Kamm
December 21, 2006
> 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 now

Hi, what about associative arrays ?
serialization\basicarchive.d(100): static assert  (0) is false, "describe called  with unsupported type"
December 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
December 21, 2006
Christian Kamm wrote:
>> 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


static if(is(A in B))

??? IIRC in only works with AAs
December 21, 2006
BCS wrote:

> Christian Kamm wrote:
>>> 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
> 
> 
> static if(is(A in B))
> 
> ??? IIRC in only works with AAs

opIn is overloadable.

-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource & #D: larsivi
December 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 == 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.

Christian
December 21, 2006
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

December 21, 2006
> 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? I've so far relied on typeof returning the type of the return value for functions, but couldn't find it in the spec. Maybe it would be best to use is(T.values VALUE == return)?

Christian
December 22, 2006
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
>> }
>
> 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'

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
}


> 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


December 22, 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