enforceNotNull

A convenience function to check for null t.

If you pass null to t, it will throw an exception. Otherwise, return NotNull!T.

enforceNotNull
(
T
string file = __FILE__
size_t line = __LINE__
)
(
T t
)
if (
is(T == class) ||
is(T == interface)
||
is(T == U*,
U
) &&
__traits(isScalar, T)
)

Examples

See_Also: http://forum.dlang.org/thread/mxpfzghydhirdtltmmvo@forum.dlang.org?page=3#post-ngtuwqiqumommfrlngjy:40forum.dlang.org

class A {}
class B : A {}
void f(NotNull!A a) {}
NotNull!B b = assumeNotNull(new B);
static assert(!__traits(compiles, { f(b); })); // TODO: I don't want this to fail.

Meta