Can't use std.algorithm.remove on a char[]?

TheGag96 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Apr 30 22:29:05 PDT 2016


On Saturday, 30 April 2016 at 19:21:30 UTC, ag0aep6g wrote:
> On 30.04.2016 21:08, Jon D wrote:
>> If an initial step is to fix the documentation, it would be 
>> helpful to
>> include specifically that it doesn't work with characters. 
>> It's not
>> obvious that characters don't meet the requirement.
>
> Characters are not the problem. remove works fine on a range of 
> chars, when the elements are assignable lvalues. char[] as a 
> range has neither assignable elements, nor lvalue elements. 
> That is, lines 3 and 4 here don't compile:
> ----
> import std.range: front;
> char[] a = ['f', 'o', 'o'];
> a.front = 'g';
> auto ptr = &a.front;
> ----

Why exactly is it like this? I would understand why strings 
(immutable character arrays) behave like this, but I feel like 
plain old character arrays should work the same as an array of 
ubytes when treated as a range... Or is there some other 
string-related behavior that would get broken by this?


More information about the Digitalmars-d-learn mailing list