Re: array idioms

2011-02-28 Thread Nick Treleaven
On Fri, 25 Feb 2011 23:48:19 +0100, spir wrote: > we cannot even use something like memcopy because the source & target > mem areas overlap In those cases, use memmove. But maybe there's a D-ish way that's just as efficient, not sure.

Re: array idioms

2011-02-25 Thread spir
On 02/25/2011 11:31 PM, Andrej Mitrovic wrote: On 2/25/11, spir wrote: But where is this func implemented? DMD\dmd2\src\druntime\src\rt\aaA.d _aaDel&& _aaDelX And then in object.d: extern (C) { // from druntime/src/compiler/dmd/aaA.d ... void _aaDel(void* p, TypeInfo keyti,

Re: array idioms

2011-02-25 Thread spir
On 02/25/2011 09:09 PM, Jonathan M Davis wrote: On Friday, February 25, 2011 11:30:28 spir wrote: Hello, What's the idiomatic way to: * delete an element in an associative array If you have the key, then just use remove. The online documentation for asseciative array discusses it. e.g. b.re

Re: array idioms

2011-02-25 Thread Andrej Mitrovic
On 2/25/11, spir wrote: > But where is this func > implemented? DMD\dmd2\src\druntime\src\rt\aaA.d _aaDel && _aaDelX And then in object.d: extern (C) { // from druntime/src/compiler/dmd/aaA.d ... void _aaDel(void* p, TypeInfo keyti, ...); ... } I don't really know how it gets c

Re: array idioms

2011-02-25 Thread spir
On 02/25/2011 08:55 PM, Andrej Mitrovic wrote: On 2/25/11, spir wrote: * delete an element in an associative array Just use .remove? void main() { auto var = ["a" : 1]; var.remove("b");// nothing happens var.remove("a");// "a" key is gone assert(!var.length); //

Re: array idioms

2011-02-25 Thread Jonathan M Davis
On Friday, February 25, 2011 12:51:53 Andrej Mitrovic wrote: > I have asked for remove before, I got some responses here (in fact, > Jonathan made an enhancement request for it): > > http://www.digitalmars.com/d/archives/digitalmars/D/learn/Removing_an_objec > t_from_a_range_23212.html > > The to

Re: array idioms

2011-02-25 Thread Andrej Mitrovic
I have asked for remove before, I got some responses here (in fact, Jonathan made an enhancement request for it): http://www.digitalmars.com/d/archives/digitalmars/D/learn/Removing_an_object_from_a_range_23212.html The topic was derailed, but essentially you can provide a predicate as a function

Re: array idioms

2011-02-25 Thread Jonathan M Davis
On Friday 25 February 2011 12:30:00 Andrej Mitrovic wrote: > On 2/25/11, Jonathan M Davis wrote: > >> * insert an element in a dyn array > > > > Same as remove. There's no function for doing it at the moment. > > std.array.insert: > > int[] a = [ 1, 2, 3, 4 ]; > a.insert(2, [ 1, 2 ]); > assert(

Re: array idioms

2011-02-25 Thread Jonathan M Davis
On Friday 25 February 2011 12:09:44 Jonathan M Davis wrote: > On Friday, February 25, 2011 11:30:28 spir wrote: > > * delete an element in a dyn array > > I don't think that there is one right now. There should probably be a > function in std.array which does what remove in std.container would do,

Re: array idioms

2011-02-25 Thread Jonathan M Davis
On Friday 25 February 2011 12:16:19 Steven Schveighoffer wrote: > On Fri, 25 Feb 2011 15:09:44 -0500, Jonathan M Davis > > wrote: > > On Friday, February 25, 2011 11:30:28 spir wrote: > >> Hello, > >> > >> What's the idiomatic way to: > >> > >> * delete an element in an associative array > > >

Re: array idioms

2011-02-25 Thread Andrej Mitrovic
On 2/25/11, Jonathan M Davis wrote: > >> * insert an element in a dyn array > > Same as remove. There's no function for doing it at the moment. std.array.insert: int[] a = [ 1, 2, 3, 4 ]; a.insert(2, [ 1, 2 ]); assert(a == [ 1, 2, 1, 2, 3, 4 ]); afaik insert was missing from the documentation i

Re: array idioms

2011-02-25 Thread Steven Schveighoffer
On Fri, 25 Feb 2011 15:09:44 -0500, Jonathan M Davis wrote: On Friday, February 25, 2011 11:30:28 spir wrote: Hello, What's the idiomatic way to: * delete an element in an associative array If you have the key, then just use remove. The online documentation for asseciative array discusse

Re: array idioms

2011-02-25 Thread Jonathan M Davis
On Friday, February 25, 2011 11:30:28 spir wrote: > Hello, > > What's the idiomatic way to: > > * delete an element in an associative array If you have the key, then just use remove. The online documentation for asseciative array discusses it. e.g. b.remove("hello"); If you're looking to remo

Re: array idioms

2011-02-25 Thread Andrej Mitrovic
On 2/25/11, spir wrote: > * delete an element in an associative array Just use .remove? void main() { auto var = ["a" : 1]; var.remove("b");// nothing happens var.remove("a");// "a" key is gone assert(!var.length); // empty }

array idioms

2011-02-25 Thread spir
Hello, What's the idiomatic way to: * delete an element in an associative array * delete an element in a dyn array * insert an element in a dyn array Thank you, Denis -- _ vita es estrany spir.wikidot.com