View mode: basic / threaded / horizontal-split · Log in · Help
April 23, 2012
Re: Keyword to avoid not null references
On Monday, 23 April 2012 at 17:18:30 UTC, Namespace wrote:
> I thought that something like this
>
> // not_null_struct.d
>
> NotNull!(T) assumeNotNull(T : Object)(T t) {
> 	return NotNull!(T)(t);
> }
>
> @property
> NotNull!(T) makeNotNull(T : Object)() {
> 	T t = new T();
> 	
> 	return assumeNotNull(t);
> }
>
> // not_null.d which import not_null_struct.d
>
> NotNull!(Foo) _convert() {
> 	//return NotNull!(Foo)(this); // prints: Stack overflow
> 	return assumeNotNull(this);
> }
>
> alias _convert this;
>
> would allow me to convert Foo to NotNull!(Foo) implicit. But it 
> doesn't work. I get this error:
>
> not_null.d(37): Error: template instance 
> not_null_struct.assumeNotNull!(Foo) recursive expansion
>
> Line 37 is the return in the _convert method.
>
> Does anybody know why? I thought that would a smart idea...

I see, if i comment out "alias _get this;" in NotNull it works 
fine and i can implicit convert Foo to NotNull!(Foo).
But why doesn't it work shareable? In that case it would be 
nearly perfect for me.
Does anyone know how it could work? In my opinion both variants 
have to work shareable. Don't they?
April 24, 2012
Re: Keyword to avoid not null references
After i'm sure, that this is a bug: Great work again.
If this bug will be fixed soon or someone can help me to find a 
workaround, then NotNull would be exactly what I always wanted.
Next ›   Last »
1 2 3 4
Top | Discussion index | About this forum | D home