On 5/11/22 5:41 PM, ikod wrote:
On Wednesday, 11 May 2022 at 19:15:36 UTC, Steven Schveighoffer wrote:
* add some methods returning a copy of the value instead of a pointer
to value
I return a reference to the value (via `opIndex`). Can you elaborate
on why you would need it to be a copy? What is your API?
Sorry, it is safe to return reference for your implementation, as you
call `new Entry` on every insert, like standard AA. I keep entries in
preallocated vector for performance reasons and every `resize` can break
reference.
Ah yes, with a non-gc allocator, it would be important to either ensure
references do not get stale, or to at least identify the pitfalls. Maybe
the "return a copy" version is @safe, whereas the normal opIndex is @system.
That reminds me though! with this, I can experiment with preallocating
(reserve) entries, something that is oft-requested for AA.
-Steve