char[] + utf-8 + canFind == bug?
Jonathan M Davis
jmdavisProg at gmx.com
Tue Nov 22 13:11:40 PST 2011
On Tuesday, November 22, 2011 18:02:53 Andrea Fontana wrote:
> dchar works but simple solution doesn't.
>
> code:
>
> char[] chars = "òà";
> chars.canFind('à');
>
> It says:
>
> Error: cannot implicitly convert expression ("\xc3\xb2\xc3\xa0") of type
> string to char[]
> Error: template std.algorithm.canFind(alias pred = "a == b",Range,V) if
> (is(typeof(find!(pred)(range,value)))) does not match any function
> template declaration
> Error: template std.algorithm.canFind(alias pred = "a == b",Range,V) if
> (is(typeof(find!(pred)(range,value)))) cannot deduce template function
> from argument types !()(char[],wchar)
Ah. Yes. String literals are immutable (at least in Linux). So, you'de need to
dup it if you want a mutable char[] instead of a string. The normal case is to
use a string though, so unless you actually want to mutate the characters in
the array (which is frequently an iffy thing to do with char[], since you have
to worry about not screwing up the code points), you should use string.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list