array question

Simen Kjærås simen.kjaras at gmail.com
Mon Dec 9 14:37:17 PST 2013


On 09.12.2013 23:03, seany wrote:
> yet another array question :
>
> I have defined :
>
> alias string[] surrealNum_segments;
> alias string[string] surrealNum_segments_withID;
> surrealNum_segments_withID BAR;
>
> Is there a built in function FOO, such that i could also write:
>
> FOO(surrealNum_segments) BAR;
>
> instead of
>
> surrealNum_segments_withID BAR;
>
> i.e. that will return an Associative Array type with string keys , with an array
> as argument?
>

import std.range;

alias string[] surrealNum_segments;
alias ElementType!surrealNum_segments[string] surrealNum_segments_withID;

Or, if you don't like writing all that (say, you have 1e8 array types you want 
ID versions of):

template FOO(T : U[], U) {
     alias U[string] FOO;
}

alias FOO!surrealNum_segments surrealNum_segments_withID;

But no, there is no built-in function of this kind.

-- 
   Simen


More information about the Digitalmars-d-learn mailing list