AA initialization

Puming via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 6 07:39:58 PDT 2014


On Wednesday, 6 August 2014 at 14:38:34 UTC, Marc Schütz wrote:
> On Wednesday, 6 August 2014 at 13:15:27 UTC, Kozzi11 wrote:
>> AFAIK there is no easy way to do it. Maybe it would be fine to 
>> add some function to phobos. Something like this:
>>
>>
>> auto initAA(VT,KT)() {
>>
>> 	static struct Entry
>> 	{
>> 		Entry *next;
>> 		size_t hash;
>> 	}
>> 	
>> 	static struct Impl
>> 	{
>> 		Entry*[] buckets;
>> 		size_t nodes;
>> 		TypeInfo _keyti;
>> 		Entry*[4] binit;
>> 		
>> 		@property const(TypeInfo) keyti() const @safe pure nothrow 
>> @nogc
>> 		{ return _keyti; }
>> 	}
>>
>> 	static struct AA
>> 	{
>> 		Impl* impl;
>> 	}
>>
>> 	VT[KT] aaa;
>> 	AA* aa = cast(AA*)&aaa;
>> 	if (aa.impl is null)
>> 	{   aa.impl = new Impl();
>> 		aa.impl.buckets = aa.impl.binit[];
>> 	}
>> 	aa.impl._keyti = cast() typeid(aaa);
>> 	return aaa;
>> }
>>
>>
>> Or it would be fine if I could write something like this: auto 
>> aa = new VT[KT]();
>
> `string[string] aa = [];` would be fine, too, but it currently 
> doesn't compile.

Thanks for your clarification (and also in the other thread), so 
this is an implementation issue for builtin AAs.


More information about the Digitalmars-d-learn mailing list