diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2020-04-03 00:03:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-03 09:03:13 +0200 |
commit | d23371fdd7e68c48873e09fb9e4abd76e0c57b66 (patch) | |
tree | c5133ba40656c9d7827f3671f719cd21c2a0bca1 /lib/std/decls.nim | |
parent | 7d17cd34b8d3ef134885f9317b9799d3c5952737 (diff) | |
download | Nim-d23371fdd7e68c48873e09fb9e4abd76e0c57b66.tar.gz |
std/byaddr => std/decls (#13847)
Diffstat (limited to 'lib/std/decls.nim')
-rw-r--r-- | lib/std/decls.nim | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/std/decls.nim b/lib/std/decls.nim new file mode 100644 index 000000000..dd7d19da7 --- /dev/null +++ b/lib/std/decls.nim @@ -0,0 +1,19 @@ +# see `semLowerLetVarCustomPragma` for compiler support that enables these +# lowerings + +template byaddr*(lhs, typ, ex) = + ## Allows a syntax for lvalue reference, exact analog to + ## `auto& a = ex;` in C++ + runnableExamples: + var s = @[10,11,12] + var a {.byaddr.} = s[0] + a+=100 + doAssert s == @[110,11,12] + doAssert a is int + var b {.byaddr.}: int = s[0] + doAssert a.addr == b.addr + when typ is typeof(nil): + let tmp = addr(ex) + else: + let tmp: ptr typ = addr(ex) + template lhs: untyped = tmp[] |