Documentation of D arrays

Sebastian Biallas groups.5.sepp at spamgourmet.com
Thu Jan 11 18:47:45 PST 2007


Here is some nice example of the confusion I have with D arrays:

On the really interesting page
http://www.digitalmars.com/d/exception-safe.html
this is shown:

class Mailer
{
    void Send(Message msg)
    {
	{
	    char[] origTitle = msg.Title();
	    scope(exit) msg.SetTitle(origTitle);
	    msg.SetTitle("[Sending] " ~ origTitle);
	    Copy(msg, "Sent");
	}
	scope(success) SetTitle(msg.ID(), "Sent", msg.Title);
	scope(failure) Remove(msg.ID(), "Sent");
	SmtpSend(msg);	// do the least reliable part last
    }
}

The scope(xx) things are cool, ok. The question in this example is:

What exactly happens in msg.Title() and msg.SetTitle()? [1]
*) Does msg.Title return a reference or a copy?
*) Does msg.SetTitle copy the reference or the content?

It is (for me) not obvious that the "scope(exit)" clause really works.

[1] And another question is: Why are they names Capitalized? The
style-guide[2] says that function names should start with a lower case
letter.
[2] http://www.digitalmars.com/d/dstyle.html



More information about the Digitalmars-d mailing list