Two questions about assignments
Kenji Hara
k.hara.pg at gmail.com
Mon May 27 16:12:27 PDT 2013
On Monday, 27 May 2013 at 18:00:38 UTC, bearophile wrote:
> Do you know if it's OK to accept x3 assignment and refuse the
> a2 assignment?
>
>
> struct Foo {
> immutable(char)[4] bar;
> }
> Foo x1 = { "AA" }; // No error.
> immutable(char)[4] a1 = "AA"; // No error.
> void main() {
> Foo x2 = { "AA" }; // No error.
> Foo x3 = Foo("AA"); // No error.
> immutable(char)[4] a2 = "AA"; // Error: lengths don't match
> // for array copy, 4 = 2
> }
This is known static array initializing inconsistency between
DeclDefs scope and statement scope. I think it is a bug.
> -------------------------
>
> This is a recent change in std.typecons.tuples:
>
> //
> https://github.com/9rnsr/phobos/commit/fdcaba7226c978f281f2d237fc772c6d7913eaf3
>
>
> But from this test they don't seem to be one a subtype of the
> other:
>
>
> import std.typecons: Tuple;
> void main() {
> alias T1 = Tuple!(int, int);
> alias T2 = Tuple!(int,"x", int,"y");
> auto t1 = T1(10, 20);
> auto t2 = T2(100, 200);
> t1 = t2; // OK.
> t2 = t1; // OK?
> }
std.typecons.Tuple supports "structural assignment" before the
change.
The code also works with 2.062.
Kenji Hara
More information about the Digitalmars-d-learn
mailing list