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

Jacob Carlborg doob at me.com
Sun Feb 20 10:40:08 PST 2011


On 2011-02-20 17:12, Steven Schveighoffer wrote:
> On Sun, 20 Feb 2011 09:45:36 -0500, Jacob Carlborg <doob at me.com> wrote:
>
>> 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?
>
> 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

I'm confused about how someone can implement a library like this. Every 
time I try to use D2 it's just a PITA to use. I've used D1 and Tango for 
several years and had no problem with that.

I assume this has been discussed, did that resolve in any plans to solve 
this?

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list