Documentation of D arrays

Jarrett Billingsley kb3ctd2 at yahoo.com
Fri Jan 12 05:15:57 PST 2007


"Sebastian Biallas" <groups.5.sepp at spamgourmet.com> wrote in message 
news:eo6vbc$22c4$1 at digitaldaemon.com...

> 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.

Then change it to:

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

    if(mTitle !is title)
        mTitle[] = title;
}

No more overlapping array copy error, and you also avoid unnecessarily 
copying the array if mTitle already points to it.

At least, I guess that's what error you're talking about, that's the only 
error I get.

> 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.

Really?  ;)  I wouldn't have known that, but maybe that's just because I 
don't know much about C++.  How does "msg.getTitle(origTitle)" guarantee 
that I'm getting a copy of the title?

>> Because Walter's weird like that?
>
> Oh, I didn't know that :)

Oh!  Well, get used to it.  ;) 





More information about the Digitalmars-d mailing list