Two questions about assignments

bearophile bearophileHUGS at lycos.com
Mon May 27 11:00:37 PDT 2013


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 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?
}


Bye and thank you,
bearophile


More information about the Digitalmars-d-learn mailing list