www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Single type of a tuple return type function

reply Vino <vino.bheeman hotmail.com> writes:
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
parent reply Simen =?UTF-8?B?S2rDpnLDpXM=?= <simen.kjaras gmail.com> writes:
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
parent Vino <vino.bheeman hotmail.com> writes:
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
Jan 04