'raii' for structs

Sean Kelly sean at f4.ca
Fri Oct 27 07:07:54 PDT 2006

Don Clugston wrote:
> Any ideas?

It's not much of an answer, but how about classes constructed in place 
using alloca :-p  I'll admit I sometimes miss stack-based raii types as 
well.  An alternative would be:

struct TemporaryRoundingMode
     static TemporaryRoundingMode opCall( int mode ) {}
     void undo() {}

TemporaryRoundingMode m = TemporaryRoundingMode( x );
scope(exit) x.undo();

Still pretty messy though.


More information about the Digitalmars-d-learn mailing list