why scope(success)?

Ben Hinkle ben.hinkle at gmail.com
Tue May 9 19:36:03 PDT 2006


> Maybe... self documenting functions, listing all return values at the top?
>
> int foobar( ..etc.. )
> {
>   scope(success) return 1;
>   scope(failure) return 0;
>
> }

Does scope(failure) continue unwinding the stack? I wonder what the behavior 
is of returning from a scope(failure).


> As someone else mentioned, commiting changes to a database, perhaps 
> several, some of which are optional depending on program flow eg.
>
> int foobar( ..etc..)
> {
>   if (a) {
>     ..make changes to a..
>     scope(success) db.commit(a);
>   }
>
>   if (b) {
>     ..make changes to b..
>     scope(success) db.commit(b);
>   }
>
>   ..make changes to c..
>   db.commit(c); //no scope.. required here
>   return 1;
> }

I believe writing "scope(success) foo;" followed by the end of the current 
scope is equivalent to just writing "foo;". Maybe I'm misunderstanding the 
example.

> Regan 





More information about the Digitalmars-d mailing list