www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D array, frequently used operations.

reply "Andrew Fedoniouk" <news terrainformatica.com> writes:
Attached file is my attempt to implement standard set of array

    - remove last element and return it
    - insert element into array
    - insert array into array
    - remove element and return it
    - remove range and return its content
    - just remove range
    -  find index of the element in array

provided template allows to use these fiunctions as methods of array types:

char[] s = "world";
s.ins("hello ",0);
char c = s.pop();

assert( s == "hello worl" && c == 'd' );

Any comments will be gladly appreciated.
E.g. I would like to be able to mixin these definitions
for any arbitrary T[] but no luck so far - see commented
section at the bottom of the file.

Would be also extremely nice if ~ operations will allow
to do something like this:

char c = 'a';
char[] s = "abc";
s = s[0..1] ~ c ~ s[1..s.length];

Now it does not compile. Seems like a bug in DMD.

Andrew Fedoniouk.
Mar 20 2005
parent reply "Andrew Fedoniouk" <news terrainformatica.com> writes:
oops, attachment is here 
Mar 20 2005
parent "Andrew Fedoniouk" <news terrainformatica.com> writes:
Wrong one :)

Here is what I mean in fact 
Mar 20 2005