[Issue 6365] AutoTupleDeclaration

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jul 24 06:41:42 PDT 2011


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



--- Comment #15 from Kenji Hara <k.hara.pg at gmail.com> 2011-07-24 06:41:36 PDT ---
I found a conflict like follows:
  (double, string) (i, j) = tuple(1.2, "a");
  (var, func)(var, var) = tuple(1.2, "a");
So it is bad.


I clean up syntax, and update 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[])));
----

TupleTypeList is similar to ForeachTypeList.
http://d-programming-language.org/statement.html#ForeachStatement

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list