std/byaddr => std/decls (#13847)
This commit is contained in:
parent
7d17cd34b8
commit
d23371fdd7
3 changed files with 3 additions and 3 deletions
19
lib/std/decls.nim
Normal file
19
lib/std/decls.nim
Normal file
|
|
@ -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[]
|
||||
Loading…
Add table
Add a link
Reference in a new issue