Dynamic arrays in D 1.0

Janice Caron caron800 at googlemail.com
Sun May 11 12:31:09 PDT 2008


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];

I place this code in the public domain. Feel free to turn it into a
function. :-)
If you don't mind making a new copy, it's even easier - you can do that in one.

    array = array[0..i] ~ array[j..$];





> 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, and for comparing the
> character elements in strings with other strings, but I see little of this
> in dynamic array functionality. What am I missing ?

std.string
std.algorithm



More information about the Digitalmars-d mailing list