Single type of a tuple return type function

Simen Kjærås simen.kjaras at gmail.com
Thu Jan 4 16:09:07 UTC 2018


On Thursday, 4 January 2018 at 15:50:35 UTC, Vino wrote:
> Hi All,
>
>   Request your help, on how o find the single type of a tuple 
> return type function, eg,
>
> auto Fn (){
> Array!string a;
> Array!int b;
> Array!ulong c;
> return tuple(a, b, c);
> }
>
> if we use "ReturnType!Fn" it gives us the output as 
> (Array!string,Array!int, Array!ulong) but what is need is the 
> return type of  each of the value as
> a = Array!string; b = Array!int; c = Array!ulong
>
> void main () {
> ReturnType!Fn[0] Dcol;  //similar like this line
> writeln(Dcol[]);
> }
>
> From,
> Vino.B

ReturnType!Fn[0] tries to give you the 0th field of the tuple, 
but as the error message indicates, you can't do that without an 
instance. What you want is the *type* of the field, as given by 
typeof:

     typeof(ReturnType!Fn[0]) Dcol;

This can be made a bit simpler by noticing that ReturnType is 
unnecessary here:

     typeof(Fn()[0]) Dcol;

However, if Fn() takes a bunch of complex parameters, this might 
not actually be simpler.

--
   Simen


More information about the Digitalmars-d-learn mailing list