Andrei Alexandrescu wrote:
Jarrett Billingsley wrote:
On Tue, Mar 31, 2009 at 3:18 PM, Andrei Alexandrescu
<seewebsiteforem...@erdani.org> wrote:
import std.typecons;

Tuple!(int, float) foo()
{
   return tuple(2, 4.5);
}

The addition of the alias this feature and of constructor templates makes
std.typecons.Tuple even better.


Cool, but..

Why not just make tuples first-class types?  <_<

Why not not?

Why not remove return values in favour of out parameters?
That makes overloading on return values instantly possible, and removes complexity from the language and the compiler.

The disadvantage of not being able to use functions in expressions could be removed by library support. We can use string mixins and CTFE to do this:

void add(T)(T a, T b, out T result);

mixin(expr("assert(add(1, 2, #ret) == 3));

This is an advantage over the old design, because the complex issue about handling return values is moved from the compiler into the library, and thus is more flexible and more customizable.

Users could even write their own expr() template to support multiple return values.

Andrei

Reply via email to