Dynamic arrays in D 1.0

Edward Diener eddielee_no_spam_here at tropicsoft.com
Sun May 11 16:32:52 PDT 2008


Walter Bright wrote:
> Edward Diener 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 ?
> 
> The D string library is oriented more towards COW (copy-on-write) 
> operations rather than in-place modification. Hence, things are biased 
> towards slicing and concatenating strings.
> 
>> Furthermore in D 1.0 a char[], a dynamic array of characters, is the 
>> equivalent of the C++ std::string. In the C++ std::string class there 
>> is a rich set of functionality for manipulating the char elements in 
>> the string, for finding particular elements in the string,
> 
> std.string.find() for basic searches, std.regexp for more advanced ones.

OK, slicing gives much functionality for grabbing substrings and I 
appreciate the syntax ( I have programmed in Python ).

> 
>> and for comparing the character elements in strings with other strings,
> 
> == works for array contents, too

OK, good.

> 
>> but I see little of this in dynamic array functionality. What am I 
>> missing ?
> 
> Can you be a bit more specific about what operation(s) you want to do?

In the dynamic array world I would have expected functionlaity for 
erasing part of the array, inserting a new array at some point in the 
array, and for replacing any part of the array with another array of any 
  length. The replace is merely an erase + insert under the covers. Of 
course I am also talking about arrays of the same type.

> 
>> I am guessing this must be provided in D libraries of functions ( 
>> Phobos ? Tango ? ) templated on the dynamic array type. But, if so, 
>> this seems a poor way of providing dynamic array functionality as 
>> compared to built-in dynamic array functionality in order to provide 
>> the sort of functionality mentioned above, especially as D's dynamic 
>> arrays are part of the D language as opposed to a separate library 
>> like C++'s std::vector<T> and std::string.

Since dynamic arrays are part of the language and not a separate library 
I would have expected built-in functionality to manipulate them easily. 
Of course it can be in a library, but it seems even a general purpose 
dynamic array library does not exist for D 1.0, so that seems odd to me.



More information about the Digitalmars-d mailing list