Thread overview | |||||
---|---|---|---|---|---|
|
January 04, 2018 Single type of a tuple return type function | ||||
---|---|---|---|---|
| ||||
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 |
January 04, 2018 Re: Single type of a tuple return type function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vino | 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
|
January 04, 2018 Re: Single type of a tuple return type function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjærås | On Thursday, 4 January 2018 at 16:09:07 UTC, Simen Kjærås wrote:
> On Thursday, 4 January 2018 at 15:50:35 UTC, Vino wrote:
>> [...]
>
> 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
HI Simen,
Thank you very much, your solution was helpful.
From,
Vino.B
|
Copyright © 1999-2021 by the D Language Foundation