How to make AA key a pointer

Clinton clinton.d.skakun at gmail.com
Tue Feb 20 14:27:37 UTC 2018


On Monday, 19 February 2018 at 15:02:29 UTC, ketmar wrote:
> Clinton wrote:
>
>> On Monday, 19 February 2018 at 14:55:01 UTC, Clinton wrote:
>>> [...]
>>
>> Sorry, on second look my explanation isn't very clear. I want 
>> to know if:
>>
>> bool[string] myAA;
>>
>> myAA[contact.id] = true; // Does this copy contact.id or is 
>> this a pointer to contact.id?
>
> there is absolutely no reason to copy `string` ever, as it is 
> `immutable`. and compiler knows that. anyway, why don't you 
> just check it by writing the code first?
>
> 	import std.stdio;
> 	void main () {
> 		int[string] a;
> 		string s = "test";
> 		writefln("%08x", s.ptr);
> 		a[s] = 666;
> 		s = "test1";
> 		writefln("%08x", s.ptr);
> 		a[s] = 42;
> 		foreach (string k; a.byKey) writefln("%08x", k.ptr);
> 	}

Thanks. I actually did a similar test a little while ago and 
found it out. Thanks for confirming. I still struggle a bit with 
these basic things.


More information about the Digitalmars-d-learn mailing list