Skip to content

Instantly share code, notes, and snippets.

@PhilipWitte
Last active August 29, 2015 14:26
Show Gist options
  • Save PhilipWitte/21c09a76eab0cc9e9945 to your computer and use it in GitHub Desktop.
Save PhilipWitte/21c09a76eab0cc9e9945 to your computer and use it in GitHub Desktop.
Ptr Region Deref Overload Test
type
Automatic = object
Explicit = object
AutoRef[T] = ptr[Automatic, T]
ExplicitRef[T] = ptr[Explicit, T]
proc `[]`[T](r:AutoRef[T]): var T =
echo "Automatic"
return r[]
proc `[]`[T](r:ExplicitRef[T]): var T =
echo "Explicit"
return r[]
var ap = cast[AutoRef[int]](alloc sizeof int)
var ep = cast[ExplicitRef[int]](alloc sizeof int)
ap[] = 123
ep[] = 456
# explict use works..
let a: int = region_overload.`[]`(ap)
let e: int = region_overload.`[]`(ep)
# these dont tho..
#let a: int = ap[]
#let e: int = ep[]
echo "A: ", a
echo "E: ", e
dealloc cast[pointer](ap)
dealloc cast[pointer](ep)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment