What is the stance on partial initializers when declaring

Jacob Carlborg doob at me.com
Fri Jul 22 04:32:03 PDT 2011


On 2011-07-22 11:56, kenji hara wrote:
> I have posted a pull request for library tuple (= alias this tuple)
> unpacking somewhere:
> https://github.com/D-Programming-Language/dmd/pull/74
> (Test code) https://github.com/D-Programming-Language/dmd/pull/74/files#L7R130
>
> This patch allows unpacking tuple following places:
> - Non-template function arguments
> - Template function arguments
> - StructLiteral arguments
> - Initializer
> - foreach aggregate
> - foreach range.front
>
> And I think make enhancement patch allowing tuple declaration like follows:
> auto (i, s) = tuple(1, "str");
> TypeTuple!(string, int[]) (s, arr) = TypeTuple!("str", [1, 2]);
>
> Syntax:
> ("auto" | TupleTypeName) "(" Identifier ["," Identifier ...] ")" "="
> Initializer ";"
>
> Tuple assignment is already supported in current D like follows:
>
> import std.typetuple : seq = TypeTuple;
> void main()
> {
>    int x, y;
>    seq!(x, y) = seq!(1, 2);  // aassign
>    assert(x == 1);
>    assert(y == 2);
> }
>
> I think more language support for tuple assignment is not need.
>
> Kenji Hara
>

Cool. But it's quite inconsistent that assignment requires "seq" and 
declaration doesn't.

(x, y) = seq!(1, 2);

Would it be possible to allow the above syntax?

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list