On Sun, 20 Feb 2011 09:45:36 -0500, Jacob Carlborg <[email protected]> wrote:

On 2011-02-19 23:20, Steven Schveighoffer wrote:
On Sat, 19 Feb 2011 16:23:12 -0500, Jacob Carlborg <[email protected]> wrote:

Compiling the following code with DMD 2.052 on Mac OS X:

import std.array;

void main ()
{
char[] a;
char[] b;
a.replace(1, 3, b);
}

Results in the following error:

test.d(7): Error: template std.array.replace(T,Range) if
(isDynamicArray!(Range) && is(ElementType!(Range) : T)) does not match
any function template declaration
test.d(7): Error: template std.array.replace(T,Range) if
(isDynamicArray!(Range) && is(ElementType!(Range) : T)) cannot deduce
template function from argument types !()(char[],int,int,char[])

What am I doing wrong or isn't std.array.replace supposed to work with
char[]?

D currently suffers from a form of schizophrenia. in Phobos, char[] and
wchar[] (and related const/immutable versions) are *NOT* treated as
arrays of char and wchar. They are treated as bi-directional ranges of
dchar. The compiler does not see it this way, it thinks they are arrays.

The error in your assumption is that Range's element type is char, when
in fact it is dchar (Range is the type of the second char[]). So the
is(ElementType!(char[]) : char) fails.

-Steve

So you're saying that I can only use dstrings for anything with the same template constraint?

Yes, dstrings act like arrays according to phobos. wstrings and strings do not. Some functions have specialized versions for strings, some do not. Expect to be confused...

-Steve

Reply via email to