How to get element type of a slice?
drug
drug2004 at bk.ru
Tue Aug 17 12:49:02 UTC 2021
17.08.2021 15:21, Ferhat Kurtulmuş пишет:
> Hello folks,
>
> Hope everyone is doing fine. Considering the following code, in the
> first condition, I am extracting the type Point from the slice Point[].
> I searched in the std.traits, and could not find a neater solution
> something like ElementTypeOf!T. Is there any neater solution for it?
> Thanks in advance.
>
> ```d
> static if (isArray!VecPoint){
> VecPoint dummy;
> alias Point = typeof(dummy[0]);
> } else static if (isRandomAccessRange!VecPoint){
> alias ASeq2 = TemplateArgsOf!VecPoint;
> alias Point = ASeq2[0];
> } else
> static assert(0, typeof(VecPoint).stringof ~ " type is not
> supported");
> ```
>
> Ferhat
https://dlang.org/library/std/range/primitives/element_type.html
More information about the Digitalmars-d-learn
mailing list