summary refs log tree commit diff stats
path: root/tests/accept
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-07-31 22:39:17 +0200
committerAraq <rumpf_a@web.de>2011-07-31 22:39:17 +0200
commit3e806a374a1b42246e947965677c4a1520f3db57 (patch)
treebf2de9968a3288e5f6418eec65e4dbd6587bc07e /tests/accept
parent4f7fa0591112e70f7eacef051a215e3420f78da8 (diff)
downloadNim-3e806a374a1b42246e947965677c4a1520f3db57.tar.gz
'var T' for iterators
Diffstat (limited to 'tests/accept')
-rw-r--r--tests/accept/run/tmoditer.nim29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/accept/run/tmoditer.nim b/tests/accept/run/tmoditer.nim
new file mode 100644
index 000000000..1e6be37e4
--- /dev/null
+++ b/tests/accept/run/tmoditer.nim
@@ -0,0 +1,29 @@
+discard """
+  output: "XXXXX01234"
+"""
+
+iterator modPairs(a: var array[0..4,string]): tuple[key: int, val: var string] =
+  for i in 0..a.high:
+    yield (i, a[i])
+
+iterator modItems*[T](a: var array[0..4,T]): var T =
+  for i in 0..a.high:
+    yield a[i]
+
+var
+  arr = ["a", "b", "c", "d", "e"]
+
+for a in modItems(arr):
+  a = "X"
+
+for a in items(arr):
+  stdout.write(a)
+
+for i, a in modPairs(arr):
+  a = $i
+
+for a in items(arr):
+  stdout.write(a)
+
+echo ""
+