A Discussion of Tuple Syntax

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Aug 19 17:27:46 PDT 2013


On Tue, Aug 20, 2013 at 02:14:28AM +0200, Meta wrote:
> On Tuesday, 20 August 2013 at 00:03:48 UTC, Andrei Alexandrescu
> wrote:
> >On 8/19/13 4:48 PM, Meta wrote:
> >>I don't necessarily want built-in syntax for a library type, but
> >>making tuples first-class would be nice. I mean, it's a bummer that
> >>they can't be returned from functions. That should definitely be
> >>changed.
> >
> >return tuple(1, "a");
> 
> That's not a TypeTuple, though, it's a built-in tuple.

Sounds like you're confused about what built-in tuples are (and you
wouldn't be the first -- they're rather confusing things). They are
perhaps best thought of as template argument lists. As such, they have
no runtime value or, as Andrej puts it, they have no ABI. So it doesn't
make sense to return them from a function. What should be the meaning,
for example, of:

	template fun(A...) {
		auto fun() {
			return A;
		}
	}

?

The answer is, this code makes no sense, because you can't return
template arguments from a function. It makes as much sense as returning
a function's signature from a function. You can't do that, because a
function's signature isn't a runtime value that can be returned.

Similarly:

	return TypeTuple!(int, 1);

doesn't really make sense. The tuple (int, 1) isn't a runtime value that
you can return from a function. It's a compile-time concept that doesn't
exist at runtime.


T

-- 
MACINTOSH: Most Applications Crash, If Not, The Operating System Hangs


More information about the Digitalmars-d mailing list