Auto tuple declaration

kenji hara k.hara.pg at gmail.com
Sun Jul 24 06:43:53 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6365#c15

I have cleanuped syntax, and updated patch.
https://github.com/9rnsr/dmd/compare/expandTuples...declarationTuple
----
TupleDeclaration:
    StorageClasses ( IdentifierList ) = Initializer ;   // 1
    ( ParameterList ) = Initializer ;                   // 2-1
    ( StorageClass TupleTypeList ) = Initializer ;      // 2-2

TupleTypeList:
    TupleType
    TupleType , TupleTypeList

TupleType:
    StorageClasses BasicType Declarator
    BasicType Declarator
    StorageClasses Identifier
    Identifier
----
// Example of 1
    auto (i, j) = tuple(10, "a");
    static assert(is(typeof(i) == int));
    static assert(is(typeof(j) == string));

    const (x, y) = TypeTuple!(1, 2);
    static assert(is(typeof(x) == const(int)));
    static assert(is(typeof(y) == const(int)));

// Example of 2-1
    (int i, string j) = tuple(10, "a");
    static assert(is(typeof(i) == int));
    static assert(is(typeof(j) == string));

// Example of 2-2
    (auto c, r) = TypeTuple!('c', "har");
    static assert(is(typeof(c) == char));
    static assert(is(typeof(r) == string));

    (const x, auto y) = TypeTuple!(1, 2);
    static assert(is(typeof(x) == const(int)));
    static assert(is(typeof(y) == int));

    (auto a1, const int[] a2) = TypeTuple!([1], [2,3]);
    static assert(is(typeof(a1) == int[]));
    static assert(is(typeof(a2) == const(int[])));
----

Kenji Hara


More information about the Digitalmars-d mailing list