Last active
August 29, 2015 14:26
-
-
Save PhilipWitte/21c09a76eab0cc9e9945 to your computer and use it in GitHub Desktop.
Ptr Region Deref Overload Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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