Can non-nullable references be implemented as a library?

Kagamin spam at here.lot
Sun Nov 7 11:05:57 PST 2010


Simen kjaeraas Wrote:

> Worth adding:
> Even if non-null references/pointers cannot be perfectly implemented in a
> library, they may still be a worthwhile addition to Phobos, to mark
> function arguments and the like.

Hmm... this doesn't work:

struct NonNull(T)
{
	T value;
	this(T v)
	{
		assert(value);
		value=v;
	}
}

class A {}

void foo(NonNull!A a){}

void goo()
{
	A a=new A();
	foo(a);
}

test.d(23): Error: function test.foo (NonNull!(A) a) is not callable using argument types (A)
test.d(23): Error: cannot implicitly convert expression (a) of type test.A to NonNull!(A)


More information about the Digitalmars-d mailing list