aboutsummaryrefslogtreecommitdiffstats
path: root/docs/types.rst
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2016-10-16 05:50:46 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2016-10-19 21:02:50 +0800
commitfcba4d927ced8410fdbcd8f9863741bf20e47ba8 (patch)
treebb7ef692ad3a4fa85bbf995bff2c378c75f1e584 /docs/types.rst
parent1b3713742f10a4749e6f15b9344d8ffaef19790e (diff)
downloaddexon-solidity-fcba4d927ced8410fdbcd8f9863741bf20e47ba8.tar.gz
dexon-solidity-fcba4d927ced8410fdbcd8f9863741bf20e47ba8.tar.zst
dexon-solidity-fcba4d927ced8410fdbcd8f9863741bf20e47ba8.zip
Merge the documentation about mappings
Diffstat (limited to 'docs/types.rst')
-rw-r--r--docs/types.rst27
1 files changed, 27 insertions, 0 deletions
diff --git a/docs/types.rst b/docs/types.rst
index 5fb512d5..959d4de3 100644
--- a/docs/types.rst
+++ b/docs/types.rst
@@ -617,6 +617,33 @@ Because of this, mappings do not have a length or a concept of a key or value be
Mappings are only allowed for state variables (or as storage reference types
in internal functions).
+It is possible to mark mappings ``public`` and have Solidity create an accessor.
+The ``_KeyType`` will become a required parameter for the accessor and it will
+return ``_ValueType``.
+
+::
+
+ pragma solidity ^0.4.0;
+
+ contract MappingExample {
+ mapping(address => uint) public balances;
+
+ function update(uint newBalance) {
+ balances[msg.sender] = newBalance;
+ }
+ }
+
+ contract MappingUser {
+ function f() returns (uint) {
+ return MappingExample(<address>).balances(this);
+ }
+ }
+
+
+.. note::
+ Mappings are not iterable, but it is possible to implement a data structure on top of them.
+ For an example, see `iterable mapping <https://github.com/ethereum/dapp-bin/blob/master/library/iterable_mapping.sol>`_.
+
.. index:: assignment, ! delete, lvalue
Operators Involving LValues