Tuple

A Tuple is a an aggregate of typed values. Tuples are useful for returning a set of values from a function or for passing a set of parameters to a function.

NOTE: Since the transition from user-defined to built-in tuples, the ability to return tuples from a function has been lost. Until this issue is addressed within the language, tuples must be enclosed in a struct if they are to be returned from a function.

template Tuple (
TList...
) {}

Members

Aliases

Tuple
alias Tuple = TList
Undocumented in source.

Examples

alias Tuple!(int, real) T1;
alias Tuple!(int, long) T2;
struct Wrap( Vals... )
{
    Vals val;
}

Wrap!(T2) func( T1 val )
{
    Wrap!(T2) ret;
    ret.val[0] = val[0];
    ret.val[1] = val[0] * cast(long) val[1];
    return ret;
}

This is the original tuple example, and demonstates what should be possible with tuples. Hopefully, language support will be added for this feature soon.

alias Tuple!(int, real) T1;
alias Tuple!(int, long) T2;

T2 func( T1 val )
{
    T2 ret;
    ret[0] = val[0];
    ret[1] = val[0] * cast(long) val[1];
    return ret;
}


// tuples may be composed
alias Tuple!(int) IntTuple;
alias Tuple!(IntTuple, long) RetTuple;

// tuples are equivalent to a set of function parameters of the same type
RetTuple t = func( 1, 2.3 );

Meta