aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorChris Ward <chriswhward@gmail.com>2018-12-13 00:10:45 +0800
committerchriseth <chris@ethereum.org>2018-12-17 20:50:47 +0800
commit7b9fd4676db613a169f5e2ea105b8e02eaef9da6 (patch)
tree5fd45d6cbbe00865340c82514fd6a2534a7cf034 /docs
parent3c76f1d660426372078b6fce1088ae7be1a06336 (diff)
downloaddexon-solidity-7b9fd4676db613a169f5e2ea105b8e02eaef9da6.tar.gz
dexon-solidity-7b9fd4676db613a169f5e2ea105b8e02eaef9da6.tar.zst
dexon-solidity-7b9fd4676db613a169f5e2ea105b8e02eaef9da6.zip
Add array item deletion idiosyncracy
Diffstat (limited to 'docs')
-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``.