Re: Assosiative array pop

2014-06-26 Thread seany via Digitalmars-d-learn
On Wednesday, 25 June 2014 at 14:17:50 UTC, Meta wrote: If you want something like a hash table that preserves insertion order, you could try using an array of tuples instead. Then to pop the first element, just do 'arr = arr[1..$]'. Thank you, this is _exactly_ what I was looking for!

Re: Assosiative array pop

2014-06-26 Thread Rene Zwanenburg via Digitalmars-d-learn
On Wednesday, 25 June 2014 at 14:17:50 UTC, Meta wrote: Then to pop the first element, just do 'arr = arr[1..$]'. Or import std.array to get the range primitives for slices: import std.array; void main() { auto arr = [1, 2, 3, 4]; arr.popFront(); assert(arr.front == 2); }

Re: Assosiative array pop

2014-06-26 Thread Meta via Digitalmars-d-learn
On Thursday, 26 June 2014 at 09:21:28 UTC, seany wrote: On Wednesday, 25 June 2014 at 14:17:50 UTC, Meta wrote: If you want something like a hash table that preserves insertion order, you could try using an array of tuples instead. Then to pop the first element, just do 'arr = arr[1..$]'.

Assosiative array pop

2014-06-25 Thread seany via Digitalmars-d-learn
Given an assosiative array : int[string] k, is there a way (either phobos or tango) to pop the first element of this array and append it to another array? I can come up with a primitive soluiton: int[string] k; // populate k here int[string] j; foreach(sttring key, int val; k) { j[key] =

Re: Assosiative array pop

2014-06-25 Thread seany via Digitalmars-d-learn
Aso, I wanted to mention that I did not find much info in the manual page on this.

Re: Assosiative array pop

2014-06-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, June 25, 2014 09:30:48 seany via Digitalmars-d-learn wrote: Given an assosiative array : int[string] k, is there a way (either phobos or tango) to pop the first element of this array and append it to another array? I can come up with a primitive soluiton: int[string] k; //

Re: Assosiative array pop

2014-06-25 Thread bearophile via Digitalmars-d-learn
seany: int[string] k; // populate k here int[string] j; foreach(sttring key, int val; k) { j[key] = val; break; } This is OK, and you can encapsulate this into a little function. But you are not removing the pair from the first associative array. So you have to remove the item before

Re: Assosiative array pop

2014-06-25 Thread Meta via Digitalmars-d-learn
On Wednesday, 25 June 2014 at 09:30:54 UTC, seany wrote: Given an assosiative array : int[string] k, is there a way (either phobos or tango) to pop the first element of this array and append it to another array? I can come up with a primitive soluiton: int[string] k; // populate k here