scope(failure) considered FREAKING AWESOME

Walter Bright newshound1 at digitalmars.com
Sun Nov 8 17:04:56 PST 2009


Justin Johansson wrote:
> Walter Bright Wrote:
> 
>> Justin Johansson wrote:
>>> C++ constructors/destructors and stack-unwinding mechanism
>>> are considered FREAKING AWESOME.
>> Ok, good. Now write (using C++ RAII) the following where both 
>> transactions must succeed or neither:
>>
>> void foo()
>> {
>>      A();
>>      scope (failure) undo_A();
>>      B();
>>      scope (failure) undo_B();
>>      writeln("A and B succeeded!");
>> }
> 
> Thanks Walter; point taken.
> Glad we had this discussion :-)

No prob. It's hard to see the benefits of scope vs RAII vs 
try-catch-finally with only one thing that needs unwinding. But as soon 
as two or more are added, watch out!



More information about the Digitalmars-d mailing list