What is a tuple and why should one care?

Lutger lutger.blijdestijn at gmail.com
Fri Oct 8 06:41:58 PDT 2010


Justin Johansson wrote:

> There's a lot of (imho, pointless) discussion going on about
> tuples in D.
> 
> I've asked before and haven't any illumination, especially of Walter.
> 
> In the context of D, can someone please enlighten me as to exactly
> what a tuple is supposed to be.
> 
> The discussion so far appears to me to be focusing on syntax
> for these "tuple thing-a-m-be's" without defining what the bloody
> thing-are-might-be's are.
> 
> Thanks in advance for zen enlightenment,
> Justin Johansson

This is how I understand it:

Most simply put, tuples are ordered and compile-time-indexable lists of 
'template parameters' which may consist only of types, symbols and values 
(compile time constants). Out of templates with variadic parameters, tuple types 
of arbitrary length can be constructed. Furthermore, tuples can be constructed 
out of aggregate types with the .tupleof property. I think that's basically it: 
compile time lists of heterogeneous compile time things.

More specifically the library phobos defines:
- type tuples: consisting only of types (traits.isTypeTuple)
- expression tuples: consisting only of values and symbols that refer to 
variables (traits.isExpressionTuple)
- 'records': std.typecons.Tuple is basically a type that can create an instance 
of a type tuple with a convenient 'record' interface













More information about the Digitalmars-d mailing list