How to get the element type of an array?

Jon Degenhardt jond at noreply.com
Tue Aug 25 16:20:52 UTC 2020


On Tuesday, 25 August 2020 at 15:02:14 UTC, FreeSlave 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.

Wow, yet another way that should have been obvious! Thanks!

--Jon


More information about the Digitalmars-d-learn mailing list