scope(exit) without exception handling?

H. S. Teoh hsteoh at quickfur.ath.cx
Wed May 16 14:46:04 PDT 2012


On Wed, May 16, 2012 at 11:34:18PM +0200, Timon Gehr wrote:
> On 05/16/2012 11:09 PM, H. S. Teoh wrote:
> >
> >OK, this isn't the same as your nothrow wrapper, but the principle is
> >the same. The funcWrap template can basically call _any_ function
> >that returns _anything_.
> >
> >D just acquired whole new levels of cool for me. :-)
> >
> 
> There are still some restrictions to be sorted out though. For
> example, try it with funcWrap(&printShort,1);

Yes I noticed that compiler type inference didn't work in that case.
This is one area I really hope will be improved soon. I kept running
into this in the new AA implementation: assigning [1,2,3] to ubyte[]
works, but passing [1,2,3] to a template automatically forces it into
int[] even though the template body then tries to assign it to a
ubyte[], causing an error.

Somebody mentioned recently the idea of an opCastFrom() (which is to
opCast() as opBinaryRight() is to opBinary()) which may help here: if a
struct/class declares opCastFrom(ubyte[]), then assigning [1,2,3] to the
struct should cause the compiler to interpret the [1,2,3] as ubyte[]
instead of int[]. 


T

-- 
If Java had true garbage collection, most programs would delete themselves upon execution. -- Robert Sewell


More information about the Digitalmars-d mailing list