Documentation of D arrays

Sebastian Biallas groups.5.sepp at spamgourmet.com
Thu Jan 11 19:29:48 PST 2007


Jarrett Billingsley wrote:
> "Sebastian Biallas" <groups.5.sepp at spamgourmet.com> wrote in message 
>> 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.
> 
> I think maybe you're putting too much thought into this :)
> 
> How msg.Title and msg.SetTitle are implemented, in this case, don't really 
> matter.  They might do something like:

[snip]

And they might be implemented as:
char[] Title()
{
	return mTitle;
}

void SetTitle(char[] title)
{
	mTitle.length = title.length;
	mTitle[] = title;
}

In which case the code just fails in case of an error.

My point is, that hypothetical C++ solution can't fail, just because of
some odd implementation:
{
	std::string origTitle;
	msg.getTitle(origTitle);
	scope(exit) msg.SetTitle(origTitle);
	msg.SetTitle("[Sending] " + origTitle);
	Copy(msg, "Sent");
}
[I rely here on some imagenary scope keyword in C++]

By reading the C++ code it is /obvious/ that I have a copy of origTitle.

> How these functions are implemented would be (1) completely up to the 
> implementer of the class, and (2) for the most part, invisible to the users 
> of the class.  The code example is the same no matter how these functions 
> are implemented.

See above :)

>> [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
> 
> Because Walter's weird like that? 

Oh, I didn't know that :)



More information about the Digitalmars-d mailing list