#Unable to do a mutable pointer capture on the result of array.popOrNull()

1 messages · Page 1 of 1 (latest)

candid stirrup
#

popOrNull doesnt return a pointer it just returns the element that was removed, what exactly are you trying to do?

fluid zealot
#

no

#

you're capturing a pointer to a temporary value

#

the last value is copied from the array

#

the length is decremented

#

and then the value is returned, copied

#

with the index it once occupied now being out of bounds

candid stirrup
#

its a temporary value

#

it gets destroyed after its used, if you want to mutate it you need to assign it to a variable

fluid zealot
#

aye, temporaries are always constant values

candid stirrup
#

both allow the same thing, this not working is just because popOrNull returns a temporary

fluid zealot
#

if you mean capturing by pointer in a for loop, that's because you get an actual pointer into the actual array/slice

#

if the array/slice is mutable, you will have a mutable pointer

#

if it's constant, it will be a constant pointer