Skip to content

Instantly share code, notes, and snippets.

@andreaferretti
Last active July 13, 2016 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreaferretti/6a1caac03a7976c40c36e0cd7710a550 to your computer and use it in GitHub Desktop.
Save andreaferretti/6a1caac03a7976c40c36e0cd7710a550 to your computer and use it in GitHub Desktop.
Auto ref types
template `~`(x): auto =
var h: ref type(x)
new(h)
h[] = x
h
type Foo = object
a, b, c: ref int
d: ref seq[int]
var f = Foo(a: ~1, b: ~2, c: ~3, d: ~ @[1, 2, 3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment