Thread overview | |||||
---|---|---|---|---|---|
|
March 20, 2005 D array, frequently used operations. | ||||
---|---|---|---|---|
| ||||
Attached file is my attempt to implement standard set of array operations: pop - remove last element and return it ins - insert element into array insr - insert array into array cut - remove element and return it cutr - remove range and return its content remove - just remove range index - 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. http://terrainformatica.com |
March 20, 2005 Re: D array, frequently used operations. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Fedoniouk Attachments: | oops, attachment is here |
March 20, 2005 Re: D array, frequently used operations. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Fedoniouk Attachments: | Wrong one :) Here is what I mean in fact |
Copyright © 1999-2021 by the D Language Foundation