Dynamic arrays in D 1.0

davidl davidl at 126.com
Sun May 11 21:27:09 PDT 2008


在 Mon, 12 May 2008 03:44:38 +0800,Bill Baxter  
<dnewsgroup at billbaxter.com> 写道:

> Janice Caron wrote:
>> On 11/05/2008, Edward Diener <eddielee_no_spam_here at tropicsoft.com>  
>> wrote:
>>> In D 1.0 dynamic arrays are the equivalent of C++'s std::vector<T>,  
>>> with
>>> slicing replacing iterators in order to access some subrange of the
>>> sequence. In C++ there is functionality in std::vector::erase for  
>>> erasing
>>> elements from the vector and std::vector::insert for inserting new  
>>> elements
>>> into the vector. Where is that functionality in D's dynamic arrays ?
>>  To erase the elements from index i to index j in place:
>>      array[i..$+i-j][] = array[j..$].dup;
>>     array = array[0..$+i-j];
>
> It can be done more efficiently using memmove to shift contents down.  
> Also if you're dropping the tail end, you can just change .length.  
> Cashew's erase routine (called "dropRange") does both.
>
> --bb

I will imagine D already calls memmove to perform array overlap copy.

-- 
使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/



More information about the Digitalmars-d mailing list