[Question] Could a function return a list of arguments to call another function?

Simen Kjaeraas simen.kjaras at gmail.com
Fri Jun 28 12:43:40 PDT 2013


On Fri, 28 Jun 2013 20:07:23 +0200, MattCoder <mattcoder at hotmail.com>  
wrote:

> Hi,
>
> I would like to know if it's possible to pass the return of a function  
> as argument to another function as below:
>
> import std.stdio;
>
> auto foo(int x, int y){
> 	writeln(x, y);
> 	return 3, 4;
> }
>
> void main(){
> 	foo(foo(1,2));
> }
>
> I would like to print:
> 1 2
> 3 4
>
> PS: I tried return a tuple but it doesn't works.
>
> Thanks,
>
> Matheus.

Not directly,  no. But this should work:


import std.stdio;
import std.typecons : tuple;

auto foo(int x, int y){
	writeln(x, y);
	return tuple(3, 4);
}

void main(){
	foo(foo(1,2).tupleof);
}
-- 
Simen


More information about the Digitalmars-d-learn mailing list