And why is RAII verbose?

I have a transactional struct:

struct Tans {
 bool committed;

 this(..) {
   committed = false;
   .. set up
 } 

 void commit() {
   .. commit
   committed = true;
 }

 ~this() {
   if(!committed) {
     .. roll back commit
   }
 }
}


I want to use this in a lot of functions

void foo() {
  Trans trans(...); /// wont compile, using Trans as a type...
  auto tans = Tans(...); /// calls destructor on the blit?
}

I was looking around in stdlib, lots of structs that are RAII have 
refcounting.  I have no need for refcounting as my transactions are unique.
also I do not want to write scope(exit) everywhere, making the transaction 
instance should be all I need.

Also the need to blit here seems silly, I just want a simple scoped RAII 
transaction/lock object. 


DMD 2.065 Windows

Reply via email to