aboutsummaryrefslogtreecommitdiff
path: root/docs/markdown/snippets
diff options
context:
space:
mode:
Diffstat (limited to 'docs/markdown/snippets')
-rw-r--r--docs/markdown/snippets/add_dictionary_variable_key.md17
1 files changed, 17 insertions, 0 deletions
diff --git a/docs/markdown/snippets/add_dictionary_variable_key.md b/docs/markdown/snippets/add_dictionary_variable_key.md
new file mode 100644
index 0000000..373ce04
--- /dev/null
+++ b/docs/markdown/snippets/add_dictionary_variable_key.md
@@ -0,0 +1,17 @@
+## Adding dictionary entry using string variable as key
+
+New dictionary entry can now be added using string variable as key,
+in addition to using string literal as key.
+
+```meson
+dict = {}
+
+# A variable to be used as a key
+key = 'myKey'
+
+# Add new entry using the variable
+dict += {key : 'myValue'}
+
+# Test that the stored value is correct
+assert(dict[key] == 'myValue', 'Incorrect value retrieved from dictionary')
+```