digitalmars.D.learn - Single type of a tuple return type function
- Vino (19/19) Jan 04 2018 Hi All,
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (13/32) Jan 04 2018 ReturnType!Fn[0] tries to give you the 0th field of the tuple,
- Vino (5/19) Jan 04 2018 HI Simen,
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
Jan 04 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
Jan 04 2018
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:HI Simen, Thank you very much, your solution was helpful. 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
Jan 04 2018








Vino <vino.bheeman hotmail.com>