Re: AA invalidating pointers and references..?

2010-08-09 Thread simendsjo
bearophile wrote: simendsjo: I haven't worked much with AA's, but I find the key in aa returns a reference to the value to be handy. I think it's better than the following: int value; if( 1 in a ) value = a[1]; or a[1] in a try/catch or other implementations. Your examples have shown

AA invalidating pointers and references..?

2010-08-08 Thread simendsjo
unittest { auto a = [1:2]; auto p = 1 in a; // can p be invalidated by rehashing? // That is pointing to a different item or a memory location used for other things? auto b = a.rehash; // The spec also says it orders in place, but returns the

Re: AA invalidating pointers and references..?

2010-08-08 Thread bearophile
simendsjo: auto a = [1:2]; auto p = 1 in a; // can p be invalidated by rehashing? Yes, I presume it can. p is meant for immediate consumption only. // The spec also says it orders in place, but returns the reorganized array... // Is the spec right? That it

Re: AA invalidating pointers and references..?

2010-08-08 Thread simendsjo
On 08.08.2010 17:51, bearophile wrote: simendsjo: auto a = [1:2]; auto p = 1 in a; // can p be invalidated by rehashing? Yes, I presume it can. p is meant for immediate consumption only. // The spec also says it orders in place, but returns the reorganized

Re: AA invalidating pointers and references..?

2010-08-08 Thread bearophile
simendsjo: I haven't worked much with AA's, but I find the key in aa returns a reference to the value to be handy. I think it's better than the following: int value; if( 1 in a ) value = a[1]; or a[1] in a try/catch or other implementations. Your examples have shown me that