Skip to content

Instantly share code, notes, and snippets.

@schveiguy
Last active February 22, 2016 03:37
Show Gist options
  • Save schveiguy/d8b50b78e2f0e5ed4c46 to your computer and use it in GitHub Desktop.
Save schveiguy/d8b50b78e2f0e5ed4c46 to your computer and use it in GitHub Desktop.
D inout article
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
}
struct LocalRef(T)
{
...
ref T get() pure const { return *_ref; }
}
struct LocalRef(T)
{
...
ref T get() pure const { return *cast(T *)_ref; }
}
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