How to get the element type of an array?

FreeSlave freeslave93 at gmail.com
Tue Aug 25 15:02:14 UTC 2020


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.


More information about the Digitalmars-d-learn mailing list