Array literals
KennyTM~
kennytm at gmail.com
Sat Oct 18 12:51:48 PDT 2008
Michel Fortin wrote:
> On 2008-10-18 11:31:09 -0400, KennyTM~ <kennytm at gmail.com> said:
>
>>>> // The only change from the code above is
>>>> // swapping the order of "Hello" and "what"
>>>> import std.stdio: writefln;
>>>> void main() {
>>>> char[static][static] a = ["what", "Hello"];
>>>> writefln(a[1].length); // 5
>>>> }
>>>>
>>>> [...]
>>> For that to work, you'd also need implcit conversion from T[4] to
>>> T[5]. How are your proposing to do that?
>>
>> Pad with T.init
>
> Should I take it then that the following assertions should hold true?
>
> char[static][static] a = ["what", "Hello"];
> assert(a[0] == "what\0");
> assert(a[0] != "what");
>
> That seems completly backward.
>
Isn't it the current behavior?
auto x = ["World", "x"];
writeln(typeof(x[0]).stringof);
writeln(typeof(x[1]).stringof);
writeln(typeof(x).stringof);
writeln(x[1] == "x");
prints:
invariant(char[5u])
invariant(char[5u])
invariant(char[5u])[2u]
false
So at least it is just "not fixing an old bug" (if this is), but not
"completely backward".
More information about the Digitalmars-d
mailing list