Last active
February 22, 2016 03:37
-
-
Save schveiguy/d8b50b78e2f0e5ed4c46 to your computer and use it in GitHub Desktop.
D inout article
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
struct LocalRef(T) | |
{ | |
private T* _ref; | |
this(ref T t) { _ref = &t; } | |
ref T get() pure { return *_ref; } | |
} | |
void main() | |
{ | |
int x; | |
auto y = LocalRef!int(x); | |
y.get = 5; | |
assert(x == 5); // y is a reference of x | |
} |
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
struct LocalRef(T) | |
{ | |
... | |
ref T get() pure const { return *_ref; } | |
} |
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
struct LocalRef(T) | |
{ | |
... | |
ref T get() pure const { return *cast(T *)_ref; } | |
} |
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
struct LocalRef(T) | |
{ | |
... | |
ref T get() pure { return *_ref; } | |
ref const(T) get() pure const { return *_ref; } | |
ref immutable(T) get() pure immutable { return *_ref; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment