Multiple return value as requirements for safety and performance

pineapple via Digitalmars-d digitalmars-d at puremagic.com
Tue Dec 20 08:53:41 PST 2016


On Tuesday, 20 December 2016 at 15:42:52 UTC, Ilya Yaroshenko 
wrote:
> This thread is about mutiple values returned by _reference_. 
> Tuples can not do it, only pointers, but they are not ctfeable 
> and safe

The way to make this useful, if I'm understanding correctly, 
would not be a more concise way to express `return tuple(a, b);` 
where `tuple` is the function defined in typecons, but to make 
expressions like `return tuple(a, b).expand;` become valid and 
using a syntax like `return (a, b);` to represent them. (For 
which I would suggest also making the parentheses optional, but 
that's minutiae.)

The syntax for assigning the returned values would likely not 
look like `auto x = {return (a, b);}(); assert(x[0] == a);`. This 
because `x` would not be a tuple in the sense of 
std.typecons.Tuple, but a tuple in the sense of what you get when 
you `expand` such a type. The assignment syntax should be more 
like `auto x, y = {return (a, b);}(); assert(x == a);`. Where the 
intent is to store the two values in the same variable, I expect 
a struct like Tuple should continue to be used.

And because in these examples `a` and `b` would not be members of 
a tuple struct, it would become possible to return some or all of 
them by reference, as can currently be done for a single returned 
value.



More information about the Digitalmars-d mailing list