aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-12-17 20:52:24 +0800
committerGitHub <noreply@github.com>2018-12-17 20:52:24 +0800
commitbc85a8915f0cc8214a8b5a4be2410ac935532fa3 (patch)
tree5fd45d6cbbe00865340c82514fd6a2534a7cf034
parent3c76f1d660426372078b6fce1088ae7be1a06336 (diff)
parent7b9fd4676db613a169f5e2ea105b8e02eaef9da6 (diff)
downloaddexon-solidity-bc85a8915f0cc8214a8b5a4be2410ac935532fa3.tar.gz
dexon-solidity-bc85a8915f0cc8214a8b5a4be2410ac935532fa3.tar.zst
dexon-solidity-bc85a8915f0cc8214a8b5a4be2410ac935532fa3.zip
Merge pull request #5639 from ethereum/docs-array-delete
DOCS: Add array item deletion idiosyncrasy
-rw-r--r--docs/types.rst9
1 files changed, 8 insertions, 1 deletions
diff --git a/docs/types.rst b/docs/types.rst
index f67a6d1a..b6003fd5 100644
--- a/docs/types.rst
+++ b/docs/types.rst
@@ -1189,7 +1189,14 @@ If ``a`` is an LValue (i.e. a variable or something that can be assigned to), th
delete
------
-``delete a`` assigns the initial value for the type to ``a``. I.e. for integers it is equivalent to ``a = 0``, but it can also be used on arrays, where it assigns a dynamic array of length zero or a static array of the same length with all elements reset. For structs, it assigns a struct with all members reset. In other words, the value of ``a`` after ``delete a`` is the same as if ``a`` would be declared without assignment, with the following caveat:
+``delete a`` assigns the initial value for the type to ``a``. I.e. for integers it is
+equivalent to ``a = 0``, but it can also be used on arrays, where it assigns a dynamic
+array of length zero or a static array of the same length with all elements set to their
+initial value. ``delete a[x]`` deletes the item at index ``x`` of the array and leaves
+all other elements and the length of the array untouched. This especially means that it leaves
+a gap in the array. If you plan to remove items, a mapping is probably a better choice.
+
+For structs, it assigns a struct with all members reset. In other words, the value of ``a`` after ``delete a`` is the same as if ``a`` would be declared without assignment, with the following caveat:
``delete`` has no effect on mappings (as the keys of mappings may be arbitrary and are generally unknown). So if you delete a struct, it will reset all members that are not mappings and also recurse into the members unless they are mappings. However, individual keys and what they map to can be deleted: If ``a`` is a mapping, then ``delete a[x]`` will delete the value stored at ``x``.