Why cant I place a stuct on a funciton stack without blitting it

Byron byron.heads at gmail.com
Sat Apr 5 08:48:21 PDT 2014


On Sat, 05 Apr 2014 15:40:13 +0000, Byron wrote:

> 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

Actually it looks like an exception was causing the log to run out of 
order.

Only though it why 
Tans trans(...);  would not work


More information about the Digitalmars-d-learn mailing list