August 25, 2020 Re: How to get the element type of an array? | ||||
---|---|---|---|---|
| ||||
Posted in reply to FreeSlave | 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
|
Copyright © 1999-2021 by the D Language Foundation