Is std.array.replace supposed to work with char[]?

Jacob Carlborg doob at me.com
Sun Feb 20 06:45:36 PST 2011


On 2011-02-19 23:20, Steven Schveighoffer wrote:
> On Sat, 19 Feb 2011 16:23:12 -0500, Jacob Carlborg <doob at me.com> 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?

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list