digitalmars.D.learn - Why cant I place a stuct on a funciton stack without blitting it
- Byron (30/30) Apr 05 2014 And why is RAII verbose?
- Byron (5/47) Apr 05 2014 Actually it looks like an exception was causing the log to run out of
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (4/5) Apr 05 2014 It works in C++. The following is one way of constructing in D:
- monarch_dodra (7/10) Apr 05 2014 This does NOT call postblit nor destructor. It's an actual
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
Apr 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 WindowsActually it looks like an exception was causing the log to run out of order. Only though it why Tans trans(...); would not work
Apr 05 2014
On 04/05/2014 08:48 AM, Byron wrote:Tans trans(...); would not workIt works in C++. The following is one way of constructing in D: Tans trans = Tans(42); Ali
Apr 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.
Apr 05 2014