On Wednesday, 28 August 2019 at 04:39:23 UTC, Mike Parker wrote:
On Wednesday, 28 August 2019 at 04:19:49 UTC, Jabari Zakiya
wrote:
I have a function (say func1) that takes 1 input value (an
integer number) and outputs 4 values (2 integers and 2 arrays
of integers).
Then inside another function (say func2) I provide the 1 input
to func1 and then want to assign its 4 output values to their
appropriate final variables that will use them.
Conceptually I want to do below:
func2 { .......; (a, b, c, d) = func1(i) }
I tried using a struct but compiler keeps complaining.
Thanks for help in advance.
A struct should work just fine:
https://run.dlang.io/is/aMBGD0
import std.stdio;
struct Results {
int a, b;
int[] aa, ab;
}
Results func1() {
return Results(1, 2, [0, 1, 2, 3], [10, 11, 12]);
}
void main()
{
writeln(func1);
}
What is the compiler complaining about?
Inside func2 I create an input value for func1 and then assign
func1's 4 outputs to named variable. That's where the problems
arise. func1 does some math based on the input and generates 4
outputs.
I can't do (a, b, c,d) = func1(i) directly.
What do I do to assign the output of func1 to the individual
variables?