Filling a char array with letters and element type of char[]

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 3 05:50:35 PST 2015


On 3/3/15 4:06 AM, Tobias Pankrath wrote:
>
>> I have three questions?
>>
>> If I change the iterator which I get from algorithm, the owner data
>> will change or not?

I'm not sure about this question.

>>
>> How to use std.algorithm.fill with char types?

You cannot currently.

>>
>> What is the type of char array holds why it does not matches char?

Because D is schizophrenic ;) Phobos considers char[] arrays not to be 
arrays of char, only ranges of dchar. Unless you talk to the compiler, 
where it happily treats char[] as an array.

> I have no time to dig into this, but:
>
> is(typeof(arr.front = 'a')) does _not_ check if arr.front is of type
> char. It is true if you can assign an 'a' to arr.front.

That is the check in std.algorithm. It wants to fill the array by 
assigning 'a' to the front. In D land, char[] arrays are ranges of 
dchars, and are only READABLE. This means a char[] array can never be an 
output range. Boatloads of code specializes char[] arrays in order to 
work around this.

I guess we need another specialization (because this should be allowed, 
IMO).

-Steve


More information about the Digitalmars-d-learn mailing list