Shouldn't hasSwappableElements work on char arrays?
Steven Schveighoffer
schveiguy at yahoo.com
Thu Feb 24 12:05:44 PST 2011
On Thu, 24 Feb 2011 14:42:38 -0500, Andrej Mitrovic
<andrej.mitrovich at gmail.com> wrote:
> On 2/24/11, Jesse Phillips <jessekphillips+D at gmail.com> wrote:
>> Andrej Mitrovic Wrote:
>>
>>> Now I see why using char[] fails. It's because [ElementType!(R).init];
>>> returns a dchar[].
>>
>> Yep, Unicode for the win. dchar[] is swappable.
>>
>
> Oh looks like you're right. I can use reverse on dchar[]. Weird, I
> thought I've already tried that.
>
> P.S. Why do I have to use this gibberish syntax?:
>
> dchar[] test = to!(dchar[])("test");
>
> Isn't the compiler smart enough to do this for me automatically? It's
> a string literal..
A string literal is immutable, dchar[] is mutable. These should work:
immutable(dchar)[] test = "test";
dstring test = "test";
auto test = "test"d;
> Still, I don't see why char arrays should fail on hasSwappableElements
> when swap can be used on char arrays?
wait, you thought char[] was an array? You poor poor soul ;)
I predict we shall get 1-2 questions/claims of incredulity like this a
month until we get a real string type.
-Steve
More information about the Digitalmars-d
mailing list