xxxxxxxxxx
--- main.d
import std;
import notnull;
void main()
{
static class C
{
}
void func(ref C t)
{
t = null;
}
auto a = notNull!C;
func(a);
}
--- notnull.d
auto notNull(T, Args...)(Args args)
{
auto instance = new T(args);
return NotNull!T(instance);
}
struct NotNull(T)
{
private T _value;
ref inout(T) value() inout
{
return this._value;
}
alias value this;
void opAssign(typeof(null));
this();
private this(T value)
{
this._value = value;
}
this(V)(NotNull!V other)
{
self._value = other._value;
}
void opAssign(V)(NotNull!V other)
{
this._value = other._value;
}
}