multiple return

bearophile bearophileHUGS at lycos.com
Tue Apr 19 16:00:30 PDT 2011


%u:

> I have function which have more than one return, and the code compile and run
> but it gives rong result -I guess-, so i use tuple but the compiler can't
> return tuple.
> 
> how can I return values?
> why I can't return tuple?

Currently in D there are two ways to return multiple values from a function:
- To use a std.typecons.tuple (not a std.typetuple).
- To use "out" function arguments.

Regarding typetuples, they can't be used to return multiple values from a function because of differences in stack alignment, this means incompatible ABI of D functions and D typetuples. This is not a great thing, but I presume that doing otherwise breaks a "zero overhead" constraint Walter seems to require to D typetuples.

Given the presence of typecons tuples (and maybe in future some syntax sugar to use them in a more handy way), this is not a significant limitation. It's mostly strange to have two very different kinds of tuples in a single language.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list