Returning multiple arrays from function - struct or byref the only option?

Laeeth Isharc via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Oct 18 03:28:43 PDT 2014


Thanks for the thoughts Meta and Ali.

Laeeth.


On Wednesday, 15 October 2014 at 17:56:06 UTC, Ali Çehreli wrote:
> On 10/15/2014 09:48 AM, Laeeth Isharc wrote:
>
> > struct RetStruct
> > {
> >      double[] a;
> >      double[] b;
> > }
> >
> > RetStruct myfunction(double x)
>
> That's my preference. Tuples would work as well but they have 
> two minor issues for me:
>
> - Unlike a struct, the members are anonymous. (Yes, tuples 
> members can have names as well but not when returning or 
> creating conveniently by 'return tuple(a, b)'.)
>
> - Unlike Python, there is no automatic tuple expansion so one 
> has to refer to the members as result[0] and result[1], which 
> is less readable than struct members. (Yes, there is some 
> support for tuple expansion e.g. in foreach but it has some 
> issues with the automatic foreach loop counter.)
>
> Summary: I return by struct. :)
>
> Ali



More information about the Digitalmars-d-learn mailing list