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!
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);
}
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..$]'.
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] =
Aso, I wanted to mention that I did not find much info in the
manual page on this.
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;
//
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
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