Question about wchar[]
Ali Çehreli
acehreli at yahoo.com
Mon Feb 4 10:22:07 PST 2013
On 02/04/2013 10:13 AM, ollie wrote:
> I am using wchar[] and find the usage clunky. Am I doing something wrong?
>
> Example:
> // Compiler complains that wchar[] != immutable(char)[]
> wchar[] wstr = "This is a wchar[]";
There is nothing but a wchar slice that is going to provide access to
the chars on the right-hand side. Unfortunately that is not possible
because neither the right-hand side has wchars nor they are mutable.
> // Compiler accepts this
> wchar[] wstr = "This is a wchar[]"w.dup;
That's fine: You explicitly make a mutable wchar array.
> // Compiler accepts this
> wchar[] wstr;
> wstr ~= "This is a wchar[]";
That's fine because the binary ~ operator always makes copies of elements.
> If the compiler knows the type in the last example with concatenation,
> shouldn't it be able to figure that out in the first example.
The missing bit is that a copy of the char literal itself is not made
automatically.
Ali
More information about the Digitalmars-d-learn
mailing list