Thread overview
Why cant I place a stuct on a funciton stack without blitting it
Apr 05, 2014
Byron
Apr 05, 2014
Byron
Apr 05, 2014
Ali Çehreli
Apr 05, 2014
monarch_dodra
April 05, 2014
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

April 05, 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
April 05, 2014
On 04/05/2014 08:48 AM, Byron wrote:

> Tans trans(...);  would not work

It works in C++. The following is one way of constructing in D:

      Tans trans = Tans(42);

Ali

April 05, 2014
On Saturday, 5 April 2014 at 15:40:13 UTC, Byron wrote:
>   auto tans = Tans(...); /// calls destructor on the blit?

This does NOT call postblit nor destructor. It's an actual declaration syntax.

> auto tans = Tans.init;

Will not call postblit either.

Finally:

> auto tans = makeTans(args...);

is guaranteed (by spec) to not call postblit if "makeTans" qualifies for [N]RVO.