parent
6ce6bce12e
commit
465815e894
2 changed files with 23 additions and 2 deletions
|
|
@ -60,3 +60,24 @@ template create(typ: typeDesc, arg: untyped): untyped = `init typ`(arg)
|
|||
var ff = Foo.create(12)
|
||||
|
||||
echo ff.arg
|
||||
|
||||
|
||||
import macros
|
||||
|
||||
# bug #11494
|
||||
macro staticForEach(arr: untyped, body: untyped): untyped =
|
||||
result = newNimNode(nnkStmtList)
|
||||
arr.expectKind(nnkBracket)
|
||||
for n in arr:
|
||||
let b = copyNimTree(body)
|
||||
result.add quote do:
|
||||
block:
|
||||
type it {.inject.} = `n`
|
||||
`b`
|
||||
|
||||
template forEveryMatchingEntity*() =
|
||||
staticForEach([int, string, float]):
|
||||
var a {.inject.}: it
|
||||
echo a
|
||||
|
||||
forEveryMatchingEntity()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue