On 2013-08-21 00:38:30 +0000, Andrei Alexandrescu <seewebsiteforem...@erdani.org> said:

1. What do we need?

I think D needs less tuples. It has two kinds (language kind and Phobos's kind), which is confusing. It should have just one that covers most use cases.

So in essence a tuple should:

1. be able to contain anything you can put as a template argument
2. be able to be packed and expanded as needed

And the above should be usable in these situations:

- using a type tuple as a variable's type
- unpacking a tuple as function/template arguments
- using a tuple as a return type
- assigning a value tuple to an alias-of-variables tuples
- using foreach with a tuple
- pass a tuple by reference to a function
- return a tuple by reference from a function
- slice a tuple
- concat tuples

I'm on the fence about taking the address of a tuple. Not being able to take the address has an upside: if the function call ABI pass each component of a tuple as one ref parameter under the hood, then you could pass tuple of aliases as function arguments. For instance, here I'd be swapping variables a, c, and e with variables b, d, and f with just one call to swap:

        int a, b, c, d, e, f;
        swap(...(a, c, e), ...(b, d, f));

(Note: using "..." syntax to create packed tuple literals. See my other post about how that'd work.)

--
Michel Fortin
michel.for...@michelf.ca
http://michelf.ca

Reply via email to