pop() that returns the last element is a method I have found would be good to have in smart contract development. Since v0.5.0 released a year ago, Solidity supports pop() for removing the last element of an array, but without returning it. Do other languages like Vyper support pop() (with last element returned), is there any plans for Solidity to support it, is the logic easily implemented in assembly?
edit: more or less pop() with assembly for 2 dimensional array.
function pop(uint _arraySlot, uint _idx) public returns (uint popped) {
assembly {
let arrayData:= keccak256(_arraySlot)
let len := sub(sload(add(arrayData, _idx)), 1)
popped := sload(add(keccak256(add(arrayData, _idx)), len))
sstore(add(arrayData, _idx), len)
}
}