type of array element, type of assoz key?

Christian Kamm kamm.incasoftware at shift-at-left-and-remove-this.de
Sun Aug 5 00:50:51 PDT 2007


dennis luehring wrote:

> how can i get the element type of an array at compiletime?

For dynamic arrays and associative arrays, something like this would work:

template ArrayElementType(T : T[])
{
  alias T ArrayElementType;
}

template AATypes(T)
{
  // todo: static assert if T is no AA type here

  alias ArrayElementType!(typeof(T.keys)) key;
  alias ArrayElementType!(typeof(T.values)) value;
}

Thinking about it, it's probably simpler to just use

typeof(array[0])
typeof(aa.keys[0]), typeof(aa.values[0]).

Cheers,
Christian



More information about the Digitalmars-d mailing list