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

Jon D via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Apr 30 12:41:29 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;
> ----

I didn't mean to suggest making the documentation technically 
incorrect. Just that it be helpful in important cases that won't 
necessarily be obvious. To me, char[] is an important case, one 
that's not made obvious by listing the hasLvalueElements 
constraint by itself.

--Jon


More information about the Digitalmars-d-learn mailing list