How to get the element type of an array?
H. S. Teoh
hsteoh at quickfur.ath.cx
Tue Aug 25 15:24:45 UTC 2020
On Tue, Aug 25, 2020 at 03:02:14PM +0000, FreeSlave via Digitalmars-d-learn wrote:
> On Tuesday, 25 August 2020 at 03:41:06 UTC, Jon Degenhardt wrote:
> > What's the best way to get the element type of an array at compile
> > time?
> >
> > Something like std.range.ElementType except that works on any array
> > type. There is std.traits.ForeachType, but it wasn't clear if that
> > was the right thing.
> >
> > --Jon
>
> Why not just use typeof(a[0])
>
> It does not matter if array is empty or not. Typeof does not actually
> evaluate its expression, just the type.
+1, why didn't I think of this before. :-D
T
--
Political correctness: socially-sanctioned hypocrisy.
More information about the Digitalmars-d-learn
mailing list