DMD 0.148 - scope guard

h3 h3 at foo.bar
Mon Feb 27 01:44:48 PST 2006


John Reimer wrote:
  > Hmm... we have "static if";  why not adopt a "scope if"?
> 
> Here's a sample using Walter's Mailer example from
> http://www.digitalmars.com/d/exception-safe.html:
> 
> # class Mailer
> # {
> #     void Send( Message msg )
> #     {
> #          {
> #              char[] origTitle = msg.Title();
> #              
> #              scope if (exit)
> #                  msg.SetTitle( origTitle );
> #              
> #              msg.SetTitle("[Sending] " ~ origTitle);
> #	       Copy(msg, "Sent");
> #          }
> #	   scope if(success) 
> #              SetTitle(msg.ID(), "Sent", msg.Title);
> #          scope if (failure)
> #             Remove(msg.ID(), "Sent");
> #          SmtpSend(msg);    // do the least reliable part last
> #      }
> # }
> 
> Simple, clear, and parallel to other D constructs, no?  We've certainly come to
> enjoy the "static if" syntax.

Looks the best so far, but it implies making 'scope', 'success' and 
'failure' keywords. Not that I recall ever using them as identifiers...



More information about the Digitalmars-d mailing list